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
|
||||
}
|
||||
|
||||
func New(rtm *rt.Runtime) Bait {
|
||||
b := Bait{
|
||||
func New(rtm *rt.Runtime) *Bait {
|
||||
b := &Bait{
|
||||
handlers: make(map[string][]*Listener),
|
||||
rtm: rtm,
|
||||
}
|
||||
|
|
|
@ -2,20 +2,20 @@ package commander
|
|||
|
||||
import (
|
||||
"hilbish/util"
|
||||
"hilbish/golibs/bait"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
"github.com/arnodel/golua/lib/packagelib"
|
||||
"github.com/chuckpreslar/emission"
|
||||
)
|
||||
|
||||
type Commander struct{
|
||||
Events *emission.Emitter
|
||||
Events *bait.Bait
|
||||
Loader packagelib.Loader
|
||||
}
|
||||
|
||||
func New() Commander {
|
||||
func New(rtm *rt.Runtime) Commander {
|
||||
c := Commander{
|
||||
Events: emission.NewEmitter(),
|
||||
Events: bait.New(rtm),
|
||||
}
|
||||
c.Loader = packagelib.Loader{
|
||||
Load: c.loaderFunc,
|
||||
|
|
11
lua.go
11
lua.go
|
@ -32,12 +32,17 @@ func luaInit() {
|
|||
lib.LoadLibs(l, fs.Loader)
|
||||
lib.LoadLibs(l, terminal.Loader)
|
||||
|
||||
cmds := commander.New()
|
||||
cmds := commander.New(l)
|
||||
// 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
|
||||
})
|
||||
cmds.Events.On("commandDeregister", func(cmdName string) {
|
||||
cmds.Events.On("commandDeregister", func(args ...interface{}) {
|
||||
cmdName := args[0].(string)
|
||||
|
||||
delete(commands, cmdName)
|
||||
})
|
||||
lib.LoadLibs(l, cmds.Loader)
|
||||
|
|
Loading…
Reference in New Issue