MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / singlevaraux

Function singlevaraux

extlibs/lua/src/lparser.c:416–437  ·  view source on GitHub ↗

** Find a variable with the given name 'n'. If it is an upvalue, add ** this upvalue into all intermediate functions. If it is a global, set ** 'var' as 'void' as a flag. */

Source from the content-addressed store, hash-verified

414** 'var' as 'void' as a flag.
415*/
416static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
417 if (fs == NULL) /* no more levels? */
418 init_exp(var, VVOID, 0); /* default is global */
419 else {
420 int v = searchvar(fs, n, var); /* look up locals at current level */
421 if (v >= 0) { /* found? */
422 if (v == VLOCAL && !base)
423 markupval(fs, var->u.var.vidx); /* local will be used as an upval */
424 }
425 else { /* not found as local at current level; try upvalues */
426 int idx = searchupvalue(fs, n); /* try existing upvalues */
427 if (idx < 0) { /* not found? */
428 singlevaraux(fs->prev, n, var, 0); /* try upper levels */
429 if (var->k == VLOCAL || var->k == VUPVAL) /* local or upvalue? */
430 idx = newupvalue(fs, n, var); /* will be a new upvalue */
431 else /* it is a global or a constant */
432 return; /* don't need to do anything at this level */
433 }
434 init_exp(var, VUPVAL, idx); /* new or old upvalue */
435 }
436 }
437}
438
439
440/*

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