SHARE
TWEET

Untitled

tinyevil Feb 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. LUA_API int lua_setmetatable (lua_State *L, int objindex) {
  3.   TValue *obj;
  4.   Table *mt;
  5.   lua_lock(L);
  6.   api_checknelems(L, 1);
  7.   obj = index2addr(L, objindex);
  8.   api_checkvalidindex(L, obj);
  9.   if (ttisnil(L->top - 1))
  10.     mt = NULL;
  11.   else {
  12.     api_check(L, ttistable(L->top - 1), "table expected");
  13.     mt = hvalue(L->top - 1);
  14.   }
  15.   switch (ttypenv(obj)) {
  16.     case LUA_TTABLE: {
  17.       hvalue(obj)->metatable = mt;
  18.       if (mt)
  19.         luaC_objbarrierback(L, gcvalue(obj), mt);
  20.         luaC_checkfinalizer(L, gcvalue(obj), mt);
  21.       break;
  22.     }
  23.     case LUA_TUSERDATA: {
  24.       uvalue(obj)->metatable = mt;
  25.       if (mt) {
  26.         luaC_objbarrier(L, rawuvalue(obj), mt);
  27.         luaC_checkfinalizer(L, gcvalue(obj), mt);
  28.       }
  29.       break;
  30.     }
  31.     default: {
  32.       G(L)->mt[ttypenv(obj)] = mt;
  33.       break;
  34.     }
  35.   }
  36.   L->top--;
  37.   lua_unlock(L);
  38.   return 1;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top