** 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. */
| 474 | ** 'var' as 'void' as a flag. |
| 475 | */ |
| 476 | static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { |
| 477 | int v = searchvar(fs, n, var); /* look up variables at current level */ |
| 478 | if (v >= 0) { /* found? */ |
| 479 | if (!base) { |
| 480 | if (var->k == VVARGVAR) /* vararg parameter? */ |
| 481 | luaK_vapar2local(fs, var); /* change it to a regular local */ |
| 482 | if (var->k == VLOCAL) |
| 483 | markupval(fs, var->u.var.vidx); /* will be used as an upvalue */ |
| 484 | } |
| 485 | /* else nothing else to be done */ |
| 486 | } |
| 487 | else { /* not found at current level; try upvalues */ |
| 488 | int idx = searchupvalue(fs, n); /* try existing upvalues */ |
| 489 | if (idx < 0) { /* not found? */ |
| 490 | if (fs->prev != NULL) /* more levels? */ |
| 491 | singlevaraux(fs->prev, n, var, 0); /* try upper levels */ |
| 492 | if (var->k == VLOCAL || var->k == VUPVAL) /* local or upvalue? */ |
| 493 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ |
| 494 | else /* it is a global or a constant */ |
| 495 | return; /* don't need to do anything at this level */ |
| 496 | } |
| 497 | init_exp(var, VUPVAL, idx); /* new or old upvalue */ |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | |
| 502 | static void buildglobal (LexState *ls, TString *varname, expdesc *var) { |
no test coverage detected