Advertisement
Guest User

Untitled

a guest
Jun 26th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. void LuaVoxelManip::Register(lua_State *L)
  2. {
  3.     /*
  4.         Regular version of the class
  5.     */
  6.     lua_newtable(L);
  7.     int methodtable = lua_gettop(L);
  8.     luaL_newmetatable(L, className);
  9.     int metatable = lua_gettop(L);
  10.  
  11.     lua_pushliteral(L, "__metatable");
  12.     lua_pushvalue(L, methodtable);
  13.     lua_settable(L, metatable);  // hide metatable from Lua getmetatable()
  14.  
  15.     lua_pushliteral(L, "__index");
  16.     lua_pushvalue(L, methodtable);
  17.     lua_settable(L, metatable);
  18.  
  19.     lua_pushliteral(L, "__gc");
  20.     lua_pushcfunction(L, gc_object);
  21.     lua_settable(L, metatable);
  22.  
  23.     lua_pop(L, 1);  // drop metatable
  24.  
  25.     luaL_openlib(L, 0, methods, 0);  // fill methodtable
  26.     lua_pop(L, 1);  // drop methodtable
  27.  
  28.     lua_register(L, className, create_object);
  29.    
  30.     /*
  31.         Non-GC version of the class
  32.     */
  33.     lua_newtable(L);
  34.     methodtable = lua_gettop(L);
  35.     luaL_newmetatable(L, className_nogc);
  36.     metatable = lua_gettop(L);
  37.  
  38.     lua_pushliteral(L, "__metatable");
  39.     lua_pushvalue(L, methodtable);
  40.     lua_settable(L, metatable);  // hide metatable from Lua getmetatable()
  41.  
  42.     lua_pushliteral(L, "__index");
  43.     lua_pushvalue(L, methodtable);
  44.     lua_settable(L, metatable);
  45.  
  46.     lua_pop(L, 1);  // drop metatable
  47.  
  48.     luaL_openlib(L, 0, methods, 0);  // fill methodtable
  49.     lua_pop(L, 1);  // drop methodtable
  50.  
  51.     lua_register(L, className_nogc, create_object);
  52. }
  53.  
  54.  
  55.     switch (mgobj) {
  56.         case MGOBJ_VMANIP: {
  57.             ManualMapVoxelManipulator *vm = mg->vm;
  58.            
  59.             // VoxelManip_nogc object
  60.             *(void **)(lua_newuserdata(L, sizeof(void *))) = vm;
  61.             luaL_getmetatable(L, "VoxelManip_nogc");
  62.             lua_setmetatable(L, -2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement