mardi 22 mars 2022

C++ Instance new Lua table with __index

I was trying to create exemplar of table in C++ which is defined in Lua. In short, i was trying to rewrite this behavior in C++

function Account:new (o)
    o = o or {}   -- create object if user does not provide one
    setmetatable(o, self)
    self.__index = self
    return o
end

int FLua::CreateTable(const char* name)
{
    LogLua(ELogVerbosity::Warning, "Creating new exemplar of table", name);

    lua_createtable(L, 0, 1);
    luaL_getmetatable(L, name);
    lua_setfield(L, -2, "__index");

    int index = luaL_ref(L, LUA_REGISTRYINDEX);

    return index;
}

This code doesnt work.

Aucun commentaire:

Enregistrer un commentaire