Find variable with given name 'n'. If it is an upvalue, add this upvalue into all intermediate functions. */
| 268 | upvalue into all intermediate functions. |
| 269 | */ |
| 270 | static 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 | |
| 295 | static void singlevar (LexState *ls, expdesc *var) { |
no test coverage detected