Find variable with given name 'n'. If it is an upvalue, add this upvalue into all intermediate functions. */
| 290 | upvalue into all intermediate functions. |
| 291 | */ |
| 292 | static int singlevaraux(FuncState *fs, TString *n, expdesc *var, int base) { |
| 293 | if (fs == nullptr) /* no more levels? */ |
| 294 | return VVOID; /* default is global */ |
| 295 | else { |
| 296 | int v = searchvar(fs, n); /* look up locals at current level */ |
| 297 | if (v >= 0) { /* found? */ |
| 298 | init_exp(var, VLOCAL, v); /* variable is local */ |
| 299 | if (!base) |
| 300 | markupval(fs, v); /* local will be used as an upval */ |
| 301 | return VLOCAL; |
| 302 | } |
| 303 | else { /* not found as local at current level; try upvalues */ |
| 304 | int idx = searchupvalue(fs, n); /* try existing upvalues */ |
| 305 | if (idx < 0) { /* not found? */ |
| 306 | if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */ |
| 307 | return VVOID; /* not found; is a global */ |
| 308 | /* else was LOCAL or UPVAL */ |
| 309 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ |
| 310 | } |
| 311 | init_exp(var, VUPVAL, idx); |
| 312 | return VUPVAL; |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | |
| 318 | static void singlevar(LexState *ls, expdesc *var) { |
no test coverage detected