Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LuaVoxelManip::Register(lua_State *L)
- {
- /*
- Regular version of the class
- */
- lua_newtable(L);
- int methodtable = lua_gettop(L);
- luaL_newmetatable(L, className);
- int metatable = lua_gettop(L);
- lua_pushliteral(L, "__metatable");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable); // hide metatable from Lua getmetatable()
- lua_pushliteral(L, "__index");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable);
- lua_pushliteral(L, "__gc");
- lua_pushcfunction(L, gc_object);
- lua_settable(L, metatable);
- lua_pop(L, 1); // drop metatable
- luaL_openlib(L, 0, methods, 0); // fill methodtable
- lua_pop(L, 1); // drop methodtable
- lua_register(L, className, create_object);
- /*
- Non-GC version of the class
- */
- lua_newtable(L);
- methodtable = lua_gettop(L);
- luaL_newmetatable(L, className_nogc);
- metatable = lua_gettop(L);
- lua_pushliteral(L, "__metatable");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable); // hide metatable from Lua getmetatable()
- lua_pushliteral(L, "__index");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable);
- lua_pop(L, 1); // drop metatable
- luaL_openlib(L, 0, methods, 0); // fill methodtable
- lua_pop(L, 1); // drop methodtable
- lua_register(L, className_nogc, create_object);
- }
- switch (mgobj) {
- case MGOBJ_VMANIP: {
- ManualMapVoxelManipulator *vm = mg->vm;
- // VoxelManip_nogc object
- *(void **)(lua_newuserdata(L, sizeof(void *))) = vm;
- luaL_getmetatable(L, "VoxelManip_nogc");
- lua_setmetatable(L, -2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement