mirror of https://github.com/Hilbis/Hilbish
feat: add commander.deregister function
simply deregisters/removes a lua defined commandpull/61/head
parent
fb04322844
commit
26eee56c8b
|
@ -20,8 +20,6 @@ func (c *Commander) Loader(L *lua.LState) int {
|
||||||
"register": c.register,
|
"register": c.register,
|
||||||
}
|
}
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
L.SetGlobal("commanding", &lua.LTable{})
|
|
||||||
L.SetField(L.GetGlobal("commanding"), "__commands", L.NewTable())
|
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
|
@ -37,3 +35,10 @@ func (c *Commander) register(L *lua.LState) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Commander) deregister(L *lua.LState) int {
|
||||||
|
cmdName := L.CheckString(1)
|
||||||
|
|
||||||
|
c.Events.Emit("commandDeregister", cmdName)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
4
lua.go
4
lua.go
|
@ -48,7 +48,9 @@ func LuaInit() {
|
||||||
cmds.Events.On("commandRegister", func(cmdName string, cmd *lua.LFunction) {
|
cmds.Events.On("commandRegister", func(cmdName string, cmd *lua.LFunction) {
|
||||||
commands[cmdName] = cmd
|
commands[cmdName] = cmd
|
||||||
})
|
})
|
||||||
|
cmds.Events.On("commandDeregister", func(cmdName string) {
|
||||||
|
delete(commands, cmdName)
|
||||||
|
})
|
||||||
l.PreloadModule("commander", cmds.Loader)
|
l.PreloadModule("commander", cmds.Loader)
|
||||||
|
|
||||||
hooks = bait.New()
|
hooks = bait.New()
|
||||||
|
|
Loading…
Reference in New Issue