MCPcopy Create free account
hub / github.com/DFHack/dfhack / lua_setmetatable

Function lua_setmetatable

depends/lua/src/lapi.c:846–883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

844
845
846LUA_API int lua_setmetatable (lua_State *L, int objindex) {
847 TValue *obj;
848 Table *mt;
849 lua_lock(L);
850 api_checknelems(L, 1);
851 obj = index2addr(L, objindex);
852 if (ttisnil(L->top - 1))
853 mt = NULL;
854 else {
855 api_check(L, ttistable(L->top - 1), "table expected");
856 mt = hvalue(L->top - 1);
857 }
858 switch (ttnov(obj)) {
859 case LUA_TTABLE: {
860 hvalue(obj)->metatable = mt;
861 if (mt) {
862 luaC_objbarrier(L, gcvalue(obj), mt);
863 luaC_checkfinalizer(L, gcvalue(obj), mt);
864 }
865 break;
866 }
867 case LUA_TUSERDATA: {
868 uvalue(obj)->metatable = mt;
869 if (mt) {
870 luaC_objbarrier(L, uvalue(obj), mt);
871 luaC_checkfinalizer(L, gcvalue(obj), mt);
872 }
873 break;
874 }
875 default: {
876 G(L)->mt[ttnov(obj)] = mt;
877 break;
878 }
879 }
880 L->top--;
881 lua_unlock(L);
882 return 1;
883}
884
885
886LUA_API void lua_setuservalue (lua_State *L, int idx) {

Callers 15

convert_to_exceptionFunction · 0.85
NewMethod · 0.85
OpenMethod · 0.85
AddFieldInfoTableFunction · 0.85
PushMethod · 0.85
dfhack_penarray_newFunction · 0.85
dfhack_random_newFunction · 0.85
freeze_tableFunction · 0.85
push_object_refMethod · 0.85
AttachEnumKeysMethod · 0.85
FillEnumKeysFunction · 0.85
FillBitfieldKeysFunction · 0.85

Calls 2

index2addrFunction · 0.85
luaC_checkfinalizerFunction · 0.85

Tested by

no test coverage detected