我知道如何定义GO函数并将其设置为全局函数(文档中的两个示例).但是,如果该函数的参数应该是预定义的表,该怎么办呢?
function calling_this_function_would_be_required(predefined_table)
print(predefined_table["something"])
end
IMAP服务器Dovecot确实提供了类似上面的内容:https://doc.dovecot.org/configuration_manual/authentication/lua_based_authentication/#examples
我还想为预定义的函数提供一个表(甚至是用户数据).但我真的不知道如何实现这一点.
设置一个全局表很容易(L.SetGlobal(...)),但如何将其添加到预期的函数中?
在围棋中添加一些功能
func CallMe(L *lua.LState) {
// How do I add a table as argument??
}
func Foo() {
L := NewState()
defer L.Close()
t := L.NewTable()
t.RawSetString("example", lua.LString("some_value"))
// I do not want a global table. I would like an expected Lua function that has _this_ table as argument
L.SetGlobal("predefined_table", t)
// Not even sure with his...
L.SetGlobal("calling_this_function_is_required", L.NewFunction©llMe))
}
如果有人能照亮我一点那就太好了:-)提前谢谢