From 2c711de9dcf7e5ca2be161283d3ff6ee4c7aa5e2 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:10:18 -0400 Subject: [PATCH] feat: add mkdir and stat functions to fs module --- golibs/fs/fs.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 9e24f94..7a9ce52 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/yuin/gopher-lua" + "layeh.com/gopher-luar" ) func Loader(L *lua.LState) int { @@ -22,6 +23,8 @@ func LuaErr(L *lua.LState, code int) { var exports = map[string]lua.LGFunction{ "cd": cd, + "mkdir": mkdir, + "stat": stat, } func cd(L *lua.LState) int { @@ -38,3 +41,21 @@ func cd(L *lua.LState) int { return 0 } +func mkdir(L *lua.LState) int { + dirname := L.ToString(1) + + // TODO: handle error here + os.Mkdir(strings.TrimSpace(dirname), 0744) + + return 0 +} + +func stat(L *lua.LState) int { + path := L.ToString(1) + + // TODO: handle error here + pathinfo, _ := os.Stat(path) + L.Push(luar.New(L, pathinfo)) + + return 1 +}