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

Function singlevaraux

depends/lua/src/lparser.c:270–292  ·  view source on GitHub ↗

Find variable with given name 'n'. If it is an upvalue, add this upvalue into all intermediate functions. */

Source from the content-addressed store, hash-verified

268 upvalue into all intermediate functions.
269*/
270static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
271 if (fs == NULL) /* no more levels? */
272 init_exp(var, VVOID, 0); /* default is global */
273 else {
274 int v = searchvar(fs, n); /* look up locals at current level */
275 if (v >= 0) { /* found? */
276 init_exp(var, VLOCAL, v); /* variable is local */
277 if (!base)
278 markupval(fs, v); /* local will be used as an upval */
279 }
280 else { /* not found as local at current level; try upvalues */
281 int idx = searchupvalue(fs, n); /* try existing upvalues */
282 if (idx < 0) { /* not found? */
283 singlevaraux(fs->prev, n, var, 0); /* try upper levels */
284 if (var->k == VVOID) /* not found? */
285 return; /* it is a global */
286 /* else was LOCAL or UPVAL */
287 idx = newupvalue(fs, n, var); /* will be a new upvalue */
288 }
289 init_exp(var, VUPVAL, idx); /* new or old upvalue */
290 }
291 }
292}
293
294
295static void singlevar (LexState *ls, expdesc *var) {

Callers 1

singlevarFunction · 0.85

Calls 5

init_expFunction · 0.85
searchvarFunction · 0.85
markupvalFunction · 0.85
searchupvalueFunction · 0.85
newupvalueFunction · 0.85

Tested by

no test coverage detected