mirror of https://github.com/Hilbis/Hilbish
refactor: use bait event emitter on commander
parent
c76337e5a4
commit
e364897b88
|
@ -29,8 +29,8 @@ type Bait struct{
|
||||||
rtm *rt.Runtime
|
rtm *rt.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(rtm *rt.Runtime) Bait {
|
func New(rtm *rt.Runtime) *Bait {
|
||||||
b := Bait{
|
b := &Bait{
|
||||||
handlers: make(map[string][]*Listener),
|
handlers: make(map[string][]*Listener),
|
||||||
rtm: rtm,
|
rtm: rtm,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@ package commander
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hilbish/util"
|
"hilbish/util"
|
||||||
|
"hilbish/golibs/bait"
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
"github.com/arnodel/golua/lib/packagelib"
|
"github.com/arnodel/golua/lib/packagelib"
|
||||||
"github.com/chuckpreslar/emission"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Commander struct{
|
type Commander struct{
|
||||||
Events *emission.Emitter
|
Events *bait.Bait
|
||||||
Loader packagelib.Loader
|
Loader packagelib.Loader
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Commander {
|
func New(rtm *rt.Runtime) Commander {
|
||||||
c := Commander{
|
c := Commander{
|
||||||
Events: emission.NewEmitter(),
|
Events: bait.New(rtm),
|
||||||
}
|
}
|
||||||
c.Loader = packagelib.Loader{
|
c.Loader = packagelib.Loader{
|
||||||
Load: c.loaderFunc,
|
Load: c.loaderFunc,
|
||||||
|
|
11
lua.go
11
lua.go
|
@ -32,12 +32,17 @@ func luaInit() {
|
||||||
lib.LoadLibs(l, fs.Loader)
|
lib.LoadLibs(l, fs.Loader)
|
||||||
lib.LoadLibs(l, terminal.Loader)
|
lib.LoadLibs(l, terminal.Loader)
|
||||||
|
|
||||||
cmds := commander.New()
|
cmds := commander.New(l)
|
||||||
// When a command from Lua is added, register it for use
|
// When a command from Lua is added, register it for use
|
||||||
cmds.Events.On("commandRegister", func(cmdName string, cmd *rt.Closure) {
|
cmds.Events.On("commandRegister", func(args ...interface{}) {
|
||||||
|
cmdName := args[0].(string)
|
||||||
|
cmd := args[1].(*rt.Closure)
|
||||||
|
|
||||||
commands[cmdName] = cmd
|
commands[cmdName] = cmd
|
||||||
})
|
})
|
||||||
cmds.Events.On("commandDeregister", func(cmdName string) {
|
cmds.Events.On("commandDeregister", func(args ...interface{}) {
|
||||||
|
cmdName := args[0].(string)
|
||||||
|
|
||||||
delete(commands, cmdName)
|
delete(commands, cmdName)
|
||||||
})
|
})
|
||||||
lib.LoadLibs(l, cmds.Loader)
|
lib.LoadLibs(l, cmds.Loader)
|
||||||
|
|
Loading…
Reference in New Issue