moonscript
moonscript copied to clipboard
How can I call ls.NewClosure and set local variable
How can I call ls.NewClosure and set local variable
func Test() {
L := lua.NewState()
defer L.Close()
L.SetGlobal("i", lua.LNumber(11))
L.NewClosure(func (ls *lua.LState) int {
// what can i do at here
// maybe ls.Push ? but it's no name
// maybe ls.GetStack and ls.SetLocal, but I don't know how to set the local variable named i
ls.DoString("return i")
})
}
like lua code
i = 11
return (function()
local i = 10
return i
end)()
the return value is 10
i = 11
(->
local i
i = 10
i)!