hermeticum/server/witch/header.go

49 lines
961 B
Go
Raw Normal View History

2022-12-20 08:38:47 +00:00
package witch
import (
lua "github.com/yuin/gopher-lua"
)
2022-12-28 05:19:42 +00:00
func witchHas(l *lua.LState) int {
// TODO
2022-12-30 04:42:54 +00:00
/*
lv := l.ToTable(1)
log.Println(lv)
*/
2022-12-28 05:19:42 +00:00
return 0
}
2022-12-20 08:38:47 +00:00
// TODO provides
2022-12-28 05:19:42 +00:00
func witchHears(l *lua.LState) int {
return addHandler(l, "say")
}
func witchSees(l *lua.LState) int {
return addHandler(l, "emote")
2022-12-20 08:38:47 +00:00
}
2022-12-28 05:19:42 +00:00
func witchDoes(ls *lua.LState) int {
2022-12-22 06:38:15 +00:00
// TODO how to feed events back into the server?
// it needs to behave like an event showing up in Commands stream
// this handler needs a reference to the gateway which has a channel for sending events that the server will see?
2022-12-20 08:38:47 +00:00
return 0
}
func addHandler(l *lua.LState, verb string) int {
pattern := l.ToString(1)
cb := l.ToFunction(2)
2022-12-22 06:38:15 +00:00
2022-12-28 05:19:42 +00:00
handlers := l.GetGlobal("_handlers").(*lua.LTable)
verbHandlers, ok := handlers.RawGetString(verb).(*lua.LTable)
if !ok {
verbHandlers = l.NewTable()
handlers.RawSetString(verb, verbHandlers)
}
verbHandlers.RawSetString(pattern, cb)
2022-12-22 06:38:15 +00:00
return 0
}