** Find and reuse, or create if it does not exist, an upvalue ** at the given level. */
| 86 | ** at the given level. |
| 87 | */ |
| 88 | UpVal *luaF_findupval (lua_State *L, StkId level) { |
| 89 | UpVal **pp = &L->openupval; |
| 90 | UpVal *p; |
| 91 | lua_assert(isintwups(L) || L->openupval == NULL); |
| 92 | while ((p = *pp) != NULL && uplevel(p) >= level) { /* search for it */ |
| 93 | lua_assert(!isdead(G(L), p)); |
| 94 | if (uplevel(p) == level) /* corresponding upvalue? */ |
| 95 | return p; /* return it */ |
| 96 | pp = &p->u.open.next; |
| 97 | } |
| 98 | /* not found: create a new upvalue after 'pp' */ |
| 99 | return newupval(L, 0, level, pp); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /* |
no test coverage detected