** 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. */
| 433 | ** 'var' as 'void' as a flag. |
| 434 | */ |
| 435 | static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { |
| 436 | if (fs == NULL) /* no more levels? */ |
| 437 | init_exp(var, VVOID, 0); /* default is global */ |
| 438 | else { |
| 439 | int v = searchvar(fs, n, var); /* look up locals at current level */ |
| 440 | if (v >= 0) { /* found? */ |
| 441 | if (v == VLOCAL && !base) |
| 442 | markupval(fs, var->u.var.vidx); /* local will be used as an upval */ |
| 443 | } |
| 444 | else { /* not found as local at current level; try upvalues */ |
| 445 | int idx = searchupvalue(fs, n); /* try existing upvalues */ |
| 446 | if (idx < 0) { /* not found? */ |
| 447 | singlevaraux(fs->prev, n, var, 0); /* try upper levels */ |
| 448 | if (var->k == VLOCAL || var->k == VUPVAL) /* local or upvalue? */ |
| 449 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ |
| 450 | else /* it is a global or a constant */ |
| 451 | return; /* don't need to do anything at this level */ |
| 452 | } |
| 453 | init_exp(var, VUPVAL, idx); /* new or old upvalue */ |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
| 459 | /* |
no test coverage detected