MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / singlevaraux

Function singlevaraux

3rd/lua-5.4.3/src/lparser.c:424–445  ·  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

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

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