MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lua_setmetatable

Function lua_setmetatable

freebsd/contrib/openzfs/module/lua/lapi.c:809–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

luaB_setmetatableFunction · 0.70
createmetatableFunction · 0.70
luaL_setmetatableFunction · 0.70
zcp_user_props_listFunction · 0.50

Calls 2

index2addrFunction · 0.85
luaC_checkfinalizerFunction · 0.85

Tested by

no test coverage detected