C(++) Lua push userdata with a metatable into a table
0 replies, posted
Hi.
Recently i have been experimenting with CLua and I have run into a bit of a problem.
I have a class which I am setting a metatable for and that works fine. The problem is that when i try and push that userdata+metatable into another table, Lua says its nil.
Here is the code I'm working with:
[code]
lua_newtable(poLuaState);
lua_pushstring(poLuaState, "Some String Key");
MyClass* luaMyClass = new(lua_newMyClassdata(poLuaState, sizeof(MyClass))) MyClass(Sender.getSteamID());
luaL_getmetatable(poLuaState, "MyMetatable");
lua_setmetatable(poLuaState, -2);
lua_settable(poLuaState, -3);
[/code]
Any help is appreciated.
[editline]19th July 2014[/editline]
Ok so printing the values of the table in Lua was printing nil for some reason, even though they actually exist. So there is actually nothing wrong with this code.
[editline]19th July 2014[/editline]
I just realized I had my __tostring metamethod declared wrong.. soo ye :L boxes please.
Sorry, you need to Log In to post a reply to this thread.