// use lunaStack::push if possible.
public static void push(Lua.lua_State L, LWF.Point obj, bool gc, Lua.CharPtr metatable = null)
{
int objectId = -1;
if (!objectIdentifiers[L].TryGetValue(obj, out objectId))
{
objectId = idOffset++;
objectIdentifiers[L].Add(obj, objectId);
objects[L].Add(objectId, obj);
}
if (metatable == null)
{
metatable = LunaTraits_LWF_Point.className;
}
Lua.lua_pushstring(L, "__luna");
Lua.lua_gettable(L, Lua.LUA_GLOBALSINDEX);
int __luna = Lua.lua_gettop(L);
Luna.userdataType ud = new Luna.userdataType(
objectId: objectId, // store object in userdata
gc: gc, // collect garbage
has_env: false, // does this userdata has a table attached to it?
typeId: LunaTraits_LWF_Point.uniqueID
);
ud.ToBytes((byte[])Lua.lua_newuserdata(L, Luna.userdataType.Size));
Lua.lua_pushstring(L, metatable);
Lua.lua_gettable(L, __luna);
Lua.lua_setmetatable(L, -2);
//Luna.printStack(L);
Lua.lua_insert(L, -2); // swap __luna and userdata
Lua.lua_pop(L, 1);
}