diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.113 2017/04/20 19:53:55 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -948,11 +948,21 @@ static void codenot (FuncState *fs, expdesc *e) { | |||
948 | 948 | ||
949 | 949 | ||
950 | /* | 950 | /* |
951 | ** Check whether expression 'e' is a literal string | ||
952 | */ | ||
953 | static int isKstr (FuncState *fs, expdesc *e) { | ||
954 | return (e->k == VK && ttisstring(&fs->f->k[e->u.info])); | ||
955 | } | ||
956 | |||
957 | |||
958 | /* | ||
951 | ** Create expression 't[k]'. 't' must have its final result already in a | 959 | ** Create expression 't[k]'. 't' must have its final result already in a |
952 | ** register or upvalue. | 960 | ** register or upvalue. Upvalues can only be indexed by literal strings. |
953 | */ | 961 | */ |
954 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | 962 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { |
955 | lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL)); | 963 | lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL)); |
964 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non string? */ | ||
965 | luaK_exp2anyreg(fs, t); /* put it in a register */ | ||
956 | t->u.ind.t = t->u.info; /* register or upvalue index */ | 966 | t->u.ind.t = t->u.info; /* register or upvalue index */ |
957 | t->u.ind.idx = luaK_exp2RK(fs, k); /* R/K index for key */ | 967 | t->u.ind.idx = luaK_exp2RK(fs, k); /* R/K index for key */ |
958 | t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL; | 968 | t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL; |