func main() { var L *lua51.State L = lua51.NewState() L.OpenLibs() L.GetField(lua51.LUA_GLOBALSINDEX, "print") L.PushString("Hello World!") L.Call(1, 0) L.PushGoFunction(test) L.PushGoFunction(test) L.PushGoFunction(test) L.PushGoFunction(test) L.PushGoFunction(test2) L.PushInteger(42) L.Call(1, 0) L.Call(0, 0) L.Call(0, 0) L.Call(0, 0) L.Close() }
// look up a Lua value by its full name. If idx is 0, then this name // is assumed to start in the global table, e.g. "string.gsub". // With non-zero idx, can be used to look up subfields of a table func Lookup(L *lua.State, path string, idx int) { parts := strings.Split(path, ".") if idx != 0 { L.PushValue(idx) } else { L.GetGlobal("_G") } for _, field := range parts { L.GetField(-1, field) L.Remove(-2) // remove table } }
func isValueProxy(L *lua.State, idx int) bool { res := false if L.IsUserdata(idx) { L.GetMetaTable(idx) if !L.IsNil(-1) { L.GetField(-1, "luago.value") res = !L.IsNil(-1) L.Pop(1) } L.Pop(1) } return res }