mirror of https://github.com/Hilbis/Hilbish
feat: use commanding table to store custom commands, load preload file and set require path in go
parent
a3d8f56d78
commit
adb3c0df16
|
@ -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)
|
||||
|
||||
|
|
15
main.go
15
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue