** 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). */
| 630 | ** GC). |
| 631 | */ |
| 632 | static 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 | /* |
no test coverage detected