hermeticum/server/witch/header.go

67 lines
1.4 KiB
Go
Raw Normal View History

2022-12-20 08:38:47 +00:00
package witch
import (
2022-12-24 06:34:21 +00:00
"log"
2022-12-20 08:38:47 +00:00
"github.com/vilmibm/hermeticum/server/db"
lua "github.com/yuin/gopher-lua"
)
func hasWrapper(obj db.Object) func(*lua.LState) int {
return func(ls *lua.LState) int {
2022-12-24 06:34:21 +00:00
lv := ls.ToTable(1)
log.Println(lv)
2022-12-20 08:38:47 +00:00
return 0
}
}
func hearsWrapper(obj db.Object) func(*lua.LState) int {
return func(ls *lua.LState) int {
// TODO get handler from _handlers
// TODO call it
// TODO how to get message in here?
return 0
}
}
func does(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
}
2022-12-22 06:38:15 +00:00
/*
string -> fn does not work because there might be multiple handlers for a given verb.
i can:
- have a list of handlers. call each one. it is the handler's
responsibility to decide if it's a match or not.
- store string -> map[string]fn. do the matching in Go.
handlers = {
"hear" = {
"*eat*" = cbfn0
"*slurp*" = cbfn1
}
"see" = {
"*fork*" = cbfn2
}
}
*/
func addHandler(ls *lua.LState) int {
verb := ls.ToString(1)
pattern := ls.ToString(2)
cb := ls.ToFunction(3)
handlers := ls.GetGlobal("_handlers").(*lua.LTable)
newHandler := ls.NewTable()
newHandler.RawSetString(pattern, cb)
handlerMap := handlers.RawGetString(verb).(*lua.LTable)
handlerMap.RawSetString(verb, newHandler)
return 0
}