MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / lua_setmetatable

Function lua_setmetatable

Source/Misc/lua/src/lua.c:2546–2580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2544
2545
2546LUA_API int lua_setmetatable (lua_State *L, int objindex) {
2547TValue *obj;
2548Table *mt;
2549lua_lock(L);
2550api_checknelems(L, 1);
2551obj = index2adr(L, objindex);
2552api_checkvalidindex(L, obj);
2553if (ttisnil(L->top - 1))
2554mt = NULL;
2555else {
2556api_check(L, ttistable(L->top - 1));
2557mt = hvalue(L->top - 1);
2558}
2559switch (ttype(obj)) {
2560case LUA_TTABLE: {
2561hvalue(obj)->metatable = mt;
2562if (mt)
2563luaC_objbarriert(L, hvalue(obj), mt);
2564break;
2565}
2566case LUA_TUSERDATA: {
2567uvalue(obj)->metatable = mt;
2568if (mt)
2569luaC_objbarrier(L, rawuvalue(obj), mt);
2570break;
2571}
2572default: {
2573G(L)->mt[ttype(obj)] = mt;
2574break;
2575}
2576}
2577L->top--;
2578lua_unlock(L);
2579return 1;
2580}
2581
2582
2583LUA_API int lua_setfenv (lua_State *L, int idx) {

Callers 15

luausb_push_interfaceFunction · 0.85
luausb_push_deviceFunction · 0.85
luausb_push_transferFunction · 0.85
luausb_push_contextFunction · 0.85
make_function_auxFunction · 0.85
shared_initMethod · 0.85
destroy_instanceFunction · 0.85

Calls 1

index2adrFunction · 0.85

Tested by

no test coverage detected