I am following an example in Game Coding Complete 4th Edition, which uses LuaPlus.
In the example, and in any code i have tried myself, I am unable to register a function to lua if it has a return value of LuaObject.
LuaObject myClass::CreateFromScript(void)
{
Player* pCppInstance = new Player();
LuaObject luaInstance;
luaInstance.AssignNewTable(pLuaState);
luaInstance.SetLightUserData("__object", pCppInstance);
LuaObject metaTable = pLuaState->GetGlobals().GetByName("Players");
luaInstance.SetMetaTable(metaTable);
return luaInstance;
}
and
globals.RegisterDirect("createPlayer", &myClass::CreateFromScript);
and in .h
static LuaObject CreateFromScript(void);
The error always happens when I set the return value to LuaObject. Which is why I was unable to do this earlier when I tried returning a LuaObject with a different function in my code.
error: LuaPlusCD.h (line 158)
"no matching function for call to 'Push(lua_State*&, LuaPlus::LuaObject&)'