MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / lua_setmetatable

Function lua_setmetatable

3rd/lua-5.4.3/src/lapi.c:927–964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925
926
927LUA_API int lua_setmetatable (lua_State *L, int objindex) {
928 TValue *obj;
929 Table *mt;
930 lua_lock(L);
931 api_checknelems(L, 1);
932 obj = index2value(L, objindex);
933 if (ttisnil(s2v(L->top - 1)))
934 mt = NULL;
935 else {
936 api_check(L, ttistable(s2v(L->top - 1)), "table expected");
937 mt = hvalue(s2v(L->top - 1));
938 }
939 switch (ttype(obj)) {
940 case LUA_TTABLE: {
941 hvalue(obj)->metatable = mt;
942 if (mt) {
943 luaC_objbarrier(L, gcvalue(obj), mt);
944 luaC_checkfinalizer(L, gcvalue(obj), mt);
945 }
946 break;
947 }
948 case LUA_TUSERDATA: {
949 uvalue(obj)->metatable = mt;
950 if (mt) {
951 luaC_objbarrier(L, uvalue(obj), mt);
952 luaC_checkfinalizer(L, gcvalue(obj), mt);
953 }
954 break;
955 }
956 default: {
957 G(L)->mt[ttype(obj)] = mt;
958 break;
959 }
960 }
961 L->top--;
962 lua_unlock(L);
963 return 1;
964}
965
966
967LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {

Callers 7

luaB_setmetatableFunction · 0.85
createmetatableFunction · 0.85
luaL_setmetatableFunction · 0.85
newboxFunction · 0.85
createclibstableFunction · 0.85
db_setmetatableFunction · 0.85
db_sethookFunction · 0.85

Calls 2

index2valueFunction · 0.85
luaC_checkfinalizerFunction · 0.85

Tested by

no test coverage detected