You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
726 B
39 lines
726 B
package luaengine
|
|
|
|
import (
|
|
lua "github.com/yuin/gopher-lua"
|
|
|
|
"go-mysql-transfer/global"
|
|
)
|
|
|
|
func scriptModule(L *lua.LState) int {
|
|
t := L.NewTable()
|
|
L.SetFuncs(t, _scriptModuleApi)
|
|
L.Push(t)
|
|
return 1
|
|
}
|
|
|
|
var _scriptModuleApi = map[string]lua.LGFunction{
|
|
"rawRow": rawRow,
|
|
"rawAction": rawAction,
|
|
}
|
|
|
|
func DoScript(input map[string]interface{}, action string, rule *global.Rule) error {
|
|
L := _pool.Get()
|
|
defer _pool.Put(L)
|
|
|
|
row := L.NewTable()
|
|
paddingTable(L, row, input)
|
|
|
|
L.SetGlobal(_globalROW, row)
|
|
L.SetGlobal(_globalACT, lua.LString(action))
|
|
|
|
funcFromProto := L.NewFunctionFromProto(rule.LuaProto)
|
|
L.Push(funcFromProto)
|
|
err := L.PCall(0, lua.MultRet, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|