Major updates/patches, functionality, api
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
37
scripting/event/event.go
Normal file
37
scripting/event/event.go
Normal file
@ -0,0 +1,37 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
"meow.tf/residentsleeper/events"
|
||||
)
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
// register functions to the table
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
|
||||
// returns the module
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"on": onFunc,
|
||||
}
|
||||
|
||||
func onFunc(L *lua.LState) int {
|
||||
name := L.CheckString(1)
|
||||
handler := L.CheckFunction(2)
|
||||
|
||||
events.On(name, func(args ...interface{}) {
|
||||
L.Push(handler)
|
||||
|
||||
for _, arg := range args {
|
||||
L.Push(luar.New(L, arg))
|
||||
}
|
||||
|
||||
L.PCall(len(args), 0, handler)
|
||||
})
|
||||
|
||||
return 0
|
||||
}
|
Reference in New Issue
Block a user