fix: use RaiseError function from gopher-lua instead of Error

pull/78/head
sammyette 2021-10-17 17:55:21 -04:00
parent 51a68e24cf
commit 86013e6576
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 4 additions and 8 deletions

View File

@ -22,10 +22,6 @@ addition to the Lua standard library's I/O and fs functions.`)
return 1 return 1
} }
func luaErr(L *lua.LState, msg string) {
L.Error(lua.LString(msg), 2)
}
var exports = map[string]lua.LGFunction{ var exports = map[string]lua.LGFunction{
"cd": fcd, "cd": fcd,
"mkdir": fmkdir, "mkdir": fmkdir,
@ -41,7 +37,7 @@ func fcd(L *lua.LState) int {
err := os.Chdir(strings.TrimSpace(path)) err := os.Chdir(strings.TrimSpace(path))
if err != nil { if err != nil {
e := err.(*os.PathError).Err.Error() e := err.(*os.PathError).Err.Error()
luaErr(L, e) L.RaiseError(e)
} }
return 0 return 0
@ -61,7 +57,7 @@ func fmkdir(L *lua.LState) int {
err = os.Mkdir(path, 0744) err = os.Mkdir(path, 0744)
} }
if err != nil { if err != nil {
luaErr(L, err.Error()) L.RaiseError(err.Error())
} }
return 0 return 0
@ -74,7 +70,7 @@ func fstat(L *lua.LState) int {
pathinfo, err := os.Stat(path) pathinfo, err := os.Stat(path)
if err != nil { if err != nil {
luaErr(L, err.Error()) L.RaiseError(err.Error())
return 0 return 0
} }
statTbl := L.NewTable() statTbl := L.NewTable()
@ -95,7 +91,7 @@ func freaddir(L *lua.LState) int {
dirEntries, err := os.ReadDir(dir) dirEntries, err := os.ReadDir(dir)
if err != nil { if err != nil {
luaErr(L, err.Error()) L.RaiseError(err.Error())
return 0 return 0
} }
for _, entry := range dirEntries { for _, entry := range dirEntries {