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

Function lua_setmetatable

third-party/lua-5.2.4/src/lapi.c:812–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

810
811
812LUA_API int lua_setmetatable (lua_State *L, int objindex) {
813 TValue *obj;
814 Table *mt;
815 lua_lock(L);
816 api_checknelems(L, 1);
817 obj = index2addr(L, objindex);
818 if (ttisnil(L->top - 1))
819 mt = NULL;
820 else {
821 api_check(L, ttistable(L->top - 1), "table expected");
822 mt = hvalue(L->top - 1);
823 }
824 switch (ttypenv(obj)) {
825 case LUA_TTABLE: {
826 hvalue(obj)->metatable = mt;
827 if (mt) {
828 luaC_objbarrierback(L, gcvalue(obj), mt);
829 luaC_checkfinalizer(L, gcvalue(obj), mt);
830 }
831 break;
832 }
833 case LUA_TUSERDATA: {
834 uvalue(obj)->metatable = mt;
835 if (mt) {
836 luaC_objbarrier(L, rawuvalue(obj), mt);
837 luaC_checkfinalizer(L, gcvalue(obj), mt);
838 }
839 break;
840 }
841 default: {
842 G(L)->mt[ttypenv(obj)] = mt;
843 break;
844 }
845 }
846 L->top--;
847 lua_unlock(L);
848 return 1;
849}
850
851
852LUA_API void lua_setuservalue (lua_State *L, int idx) {

Callers 7

luaB_setmetatableFunction · 0.70
createmetatableFunction · 0.70
luaL_setmetatableFunction · 0.70
ll_seeallFunction · 0.70
luaopen_packageFunction · 0.70
db_setmetatableFunction · 0.70
db_sethookFunction · 0.70

Calls 2

index2addrFunction · 0.70
luaC_checkfinalizerFunction · 0.70

Tested by

no test coverage detected