@ -16,38 +16,42 @@ func Loader(L *lua.LState) int {
return1
}
funcLuaErr(L*lua.LState,codeint){
funcluaErr(L*lua.LState,codeint){
// TODO: Error with a table, with path and error code
L.Error(lua.LNumber(code),2)
}
varexports=map[string]lua.LGFunction{
"cd": cd,
"mkdir": mkdir,
"stat": stat,
"cd":fcd,
"mkdir":fmkdir,
"stat":fstat,
}
funccd(L*lua.LState)int{
// cd(dir)
// Changes directory to `dir`
funcfcd(L*lua.LState)int{
path:=L.CheckString(1)
err:=os.Chdir(strings.TrimSpace(path))
iferr!=nil{
switche:=err.(*os.PathError).Err.Error();e{
case"no such file or directory":
LuaErr(L,1)
luaErr(L,1)
case"not a directory":
LuaErr(L,2)
luaErr(L,2)
default:
fmt.Printf("Found unhandled error case: %s\n",e)
fmt.Printf("Report this at https://github.com/Rosettea/Hilbish/issues with the title being: \"fs: unhandled error case %s\", and show what caused it.\n",e)
LuaErr(L,213)
luaErr(L,213)
}
}
return0
}
funcmkdir(L*lua.LState)int{
// mkdir(name, recursive)
// Makes a directory called `name`. If `recursive` is true, it will create its parent directories.