MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / lua_setmetatable

Function lua_setmetatable

third-party/lua-5.5.0/src/lapi.c:964–1001  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

962
963
964LUA_API int lua_setmetatable (lua_State *L, int objindex) {
965 TValue *obj;
966 Table *mt;
967 lua_lock(L);
968 api_checkpop(L, 1);
969 obj = index2value(L, objindex);
970 if (ttisnil(s2v(L->top.p - 1)))
971 mt = NULL;
972 else {
973 api_check(L, ttistable(s2v(L->top.p - 1)), "table expected");
974 mt = hvalue(s2v(L->top.p - 1));
975 }
976 switch (ttype(obj)) {
977 case LUA_TTABLE: {
978 hvalue(obj)->metatable = mt;
979 if (mt) {
980 luaC_objbarrier(L, gcvalue(obj), mt);
981 luaC_checkfinalizer(L, gcvalue(obj), mt);
982 }
983 break;
984 }
985 case LUA_TUSERDATA: {
986 uvalue(obj)->metatable = mt;
987 if (mt) {
988 luaC_objbarrier(L, uvalue(obj), mt);
989 luaC_checkfinalizer(L, gcvalue(obj), mt);
990 }
991 break;
992 }
993 default: {
994 G(L)->mt[ttype(obj)] = mt;
995 break;
996 }
997 }
998 L->top.p--;
999 lua_unlock(L);
1000 return 1;
1001}
1002
1003
1004LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {

Callers 9

luaB_setmetatableFunction · 0.70
createmetatableFunction · 0.70
luaL_setmetatableFunction · 0.70
newboxFunction · 0.70
db_setmetatableFunction · 0.70
db_sethookFunction · 0.70
CreateEnvMethod · 0.50
handleStateCloseFunction · 0.50
pushVariableFunction · 0.50

Calls 2

index2valueFunction · 0.70
luaC_checkfinalizerFunction · 0.70

Tested by

no test coverage detected