MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / lua_setmetatable

Function lua_setmetatable

lib/lua/src/lapi.c:933–970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 8

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 3

index2valueFunction · 0.85
luaC_checkfinalizerFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected