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

Function lua_setfenv

Source/Misc/lua/src/lua.c:2583–2609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2581
2582
2583LUA_API int lua_setfenv (lua_State *L, int idx) {
2584StkId o;
2585int res = 1;
2586lua_lock(L);
2587api_checknelems(L, 1);
2588o = index2adr(L, idx);
2589api_checkvalidindex(L, o);
2590api_check(L, ttistable(L->top - 1));
2591switch (ttype(o)) {
2592case LUA_TFUNCTION:
2593clvalue(o)->c.env = hvalue(L->top - 1);
2594break;
2595case LUA_TUSERDATA:
2596uvalue(o)->env = hvalue(L->top - 1);
2597break;
2598case LUA_TTHREAD:
2599sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));
2600break;
2601default:
2602res = 0;
2603break;
2604}
2605if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
2606L->top--;
2607lua_unlock(L);
2608return res;
2609}
2610
2611
2612/*

Callers 5

luaB_setfenvFunction · 0.85
db_setfenvFunction · 0.85
createstdfileFunction · 0.85
luaopen_ioFunction · 0.85
setfenvFunction · 0.85

Calls 1

index2adrFunction · 0.85

Tested by

no test coverage detected