I have an instance of a Go Struct and will like to pass the instance to a Lua method using GopherLua.
My Go code goes like this:
dog := new(Animal)
runParam := lua.P{
Fn: L.GetGlobal("run"),
NRet: 1,
Protect: true,
}
mt := luar.MT(context.AppContext.LuaVM, dog)
userData := &lua.LTable{Metatable: *mt}
userData.Append(&lua.LUserData{Value: dog, Metatable: mt, Env: mt.LTable})
err = L.CallByParam(runParam, lua.LString("One"), userData)
if err != nil {
fmt.Println("Error while calling lua method: " + err.Error())
}
In my Lua method, accessing the properties of the Animal parameter gives error attempt to index a non-table object. My Lua goes like this:
function run(newName, ent) {
print(ent.Name)
}
Please what am I doing wrong? Passing other type (string, int) of parameter works fine.