From adb3c0df1639ab2167a35df7a1bd51db278e48ae Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 21 Mar 2021 12:42:04 -0400 Subject: [PATCH] feat: use commanding table to store custom commands, load preload file and set require path in go --- golibs/commander/commander.go | 3 ++- main.go | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/golibs/commander/commander.go b/golibs/commander/commander.go index 1b14106..cd202b3 100644 --- a/golibs/commander/commander.go +++ b/golibs/commander/commander.go @@ -20,7 +20,8 @@ func (c *Commander) Loader(L *lua.LState) int { "register": c.register, } mod := L.SetFuncs(L.NewTable(), exports) - L.SetField(mod, "__commands", L.NewTable()) + L.SetGlobal("commanding", &lua.LTable{}) + L.SetField(L.GetGlobal("commanding"), "__commands", L.NewTable()) L.Push(mod) diff --git a/main.go b/main.go index a763ab3..92512c9 100644 --- a/main.go +++ b/main.go @@ -111,11 +111,10 @@ func main() { if len(cmdArgs) == 0 { continue } if commands[cmdArgs[0]] { - fmt.Printf("%+q", cmdArgs[1:]) err := l.CallByParam(lua.P{ Fn: l.GetField( l.GetTable( - l.GetGlobal("commander"), + l.GetGlobal("commanding"), lua.LString("__commands")), cmdArgs[0]), NRet: 0, @@ -166,7 +165,7 @@ func LuaInit() { func (cmdName string, cmd *lua.LFunction) { commands[cmdName] = true l.SetField( - l.GetTable(l.GetGlobal("commander"), + l.GetTable(l.GetGlobal("commanding"), lua.LString("__commands")), cmdName, cmd) @@ -174,7 +173,15 @@ func LuaInit() { l.PreloadModule("commander", commander.Loader) - err := l.DoFile(os.Getenv("HOME") + "/.hilbishrc.lua") + l.DoString("package.path = package.path .. ';./libs/?/init.lua;/usr/share/hilbish/libs/?/init.lua'") + + err := l.DoFile("/usr/share/hilbish/preload.lua") + if err != nil { + fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.") + } + + homedir, _ := os.UserHomeDir() + err = l.DoFile(homedir + "/.hilbishrc.lua") if err != nil { panic(err) }