fix: throw lua error if fs.cd fails

pull/21/head^2
TorchedSammy 2021-03-30 23:56:37 -04:00
parent 1d22e4cdc1
commit 5dd7ce382a
1 changed files with 12 additions and 1 deletions

View File

@ -13,6 +13,11 @@ func Loader(L *lua.LState) int {
return 1
}
func LuaErr(L *lua.LState, code int) {
L.Error(lua.LNumber(code), 1)
}
var exports = map[string]lua.LGFunction{
"cd": cd,
}
@ -20,7 +25,13 @@ var exports = map[string]lua.LGFunction{
func cd(L *lua.LState) int {
path := L.ToString(1)
os.Chdir(path)
err := os.Chdir(path)
if err != nil {
switch err.(*os.PathError).Err.Error() {
case "no such file or directory":
LuaErr(L, 1)
}
}
return 0
}