mirror of
https://github.com/lua/lua
synced 2025-01-08 18:42:00 +03:00
'singlevaraux' returns result only in 'var->k'
This commit is contained in:
parent
fbd8614bdb
commit
b65252b39b
20
lparser.c
20
lparser.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.151 2016/01/05 16:22:37 roberto Exp roberto $
|
** $Id: lparser.c,v 2.152 2016/03/07 19:25:39 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -267,27 +267,26 @@ static void markupval (FuncState *fs, int level) {
|
|||||||
Find variable with given name 'n'. If it is an upvalue, add this
|
Find variable with given name 'n'. If it is an upvalue, add this
|
||||||
upvalue into all intermediate functions.
|
upvalue into all intermediate functions.
|
||||||
*/
|
*/
|
||||||
static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
|
static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
|
||||||
if (fs == NULL) /* no more levels? */
|
if (fs == NULL) /* no more levels? */
|
||||||
return VVOID; /* default is global */
|
init_exp(var, VVOID, 0); /* default is global */
|
||||||
else {
|
else {
|
||||||
int v = searchvar(fs, n); /* look up locals at current level */
|
int v = searchvar(fs, n); /* look up locals at current level */
|
||||||
if (v >= 0) { /* found? */
|
if (v >= 0) { /* found? */
|
||||||
init_exp(var, VLOCAL, v); /* variable is local */
|
init_exp(var, VLOCAL, v); /* variable is local */
|
||||||
if (!base)
|
if (!base)
|
||||||
markupval(fs, v); /* local will be used as an upval */
|
markupval(fs, v); /* local will be used as an upval */
|
||||||
return VLOCAL;
|
|
||||||
}
|
}
|
||||||
else { /* not found as local at current level; try upvalues */
|
else { /* not found as local at current level; try upvalues */
|
||||||
int idx = searchupvalue(fs, n); /* try existing upvalues */
|
int idx = searchupvalue(fs, n); /* try existing upvalues */
|
||||||
if (idx < 0) { /* not found? */
|
if (idx < 0) { /* not found? */
|
||||||
if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */
|
singlevaraux(fs->prev, n, var, 0); /* try upper levels */
|
||||||
return VVOID; /* not found; is a global */
|
if (var->k == VVOID) /* not found? */
|
||||||
|
return; /* it is a global */
|
||||||
/* else was LOCAL or UPVAL */
|
/* else was LOCAL or UPVAL */
|
||||||
idx = newupvalue(fs, n, var); /* will be a new upvalue */
|
idx = newupvalue(fs, n, var); /* will be a new upvalue */
|
||||||
}
|
}
|
||||||
init_exp(var, VUPVAL, idx);
|
init_exp(var, VUPVAL, idx); /* new or old upvalue */
|
||||||
return VUPVAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,10 +295,11 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
|
|||||||
static void singlevar (LexState *ls, expdesc *var) {
|
static void singlevar (LexState *ls, expdesc *var) {
|
||||||
TString *varname = str_checkname(ls);
|
TString *varname = str_checkname(ls);
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
|
singlevaraux(fs, varname, var, 1);
|
||||||
|
if (var->k == VVOID) { /* global name? */
|
||||||
expdesc key;
|
expdesc key;
|
||||||
singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
|
singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
|
||||||
lua_assert(var->k == VLOCAL || var->k == VUPVAL);
|
lua_assert(var->k != VVOID); /* this one must exist */
|
||||||
codestring(ls, &key, varname); /* key is variable name */
|
codestring(ls, &key, varname); /* key is variable name */
|
||||||
luaK_indexed(fs, var, &key); /* env[varname] */
|
luaK_indexed(fs, var, &key); /* env[varname] */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user