38 lines
569 B
Go

package fs
import (
"os"
luajit "git.sharkk.net/Sky/LuaJIT-to-Go"
)
func GetFunctionList() map[string]luajit.GoFunction {
return map[string]luajit.GoFunction{
"getcwd": getcwd,
"chdir": chdir,
}
}
func getcwd(s *luajit.State) int {
cwd, err := os.Getwd()
if err != nil {
s.PushNil()
s.PushString(err.Error())
return 2
}
s.PushString(cwd)
return 1
}
func chdir(s *luajit.State) int {
path := s.ToString(1)
err := os.Chdir(path)
if err != nil {
s.PushBoolean(false)
s.PushString(err.Error())
return 2
}
s.PushBoolean(true)
return 1
}