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

Function pushclosure

depends/lua/src/lvm.c:632–650  ·  view source on GitHub ↗

** create a new Lua closure, push it in the stack, and initialize ** its upvalues. Note that the closure is not cached if prototype is ** already black (which means that 'cache' was already cleared by the ** GC). */

Source from the content-addressed store, hash-verified

630** GC).
631*/
632static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
633 StkId ra) {
634 int nup = p->sizeupvalues;
635 Upvaldesc *uv = p->upvalues;
636 int i;
637 LClosure *ncl = luaF_newLclosure(L, nup);
638 ncl->p = p;
639 setclLvalue(L, ra, ncl); /* anchor new closure in stack */
640 for (i = 0; i < nup; i++) { /* fill in its upvalues */
641 if (uv[i].instack) /* upvalue refers to local variable? */
642 ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);
643 else /* get upvalue from enclosing function */
644 ncl->upvals[i] = encup[uv[i].idx];
645 ncl->upvals[i]->refcount++;
646 /* new closure is white, so we do not need a barrier here */
647 }
648 if (!isblack(p)) /* cache will not break GC invariant? */
649 p->cache = ncl; /* save it on cache for reuse */
650}
651
652
653/*

Callers 1

luaV_executeFunction · 0.85

Calls 2

luaF_newLclosureFunction · 0.85
luaF_findupvalFunction · 0.85

Tested by

no test coverage detected