** Create expression 't[k]'. 't' must have its final result already in a ** register or upvalue. Upvalues can only be indexed by literal strings. ** Keys can be literal strings in the constant table or arbitrary ** values in registers. */
| 1277 | ** values in registers. |
| 1278 | */ |
| 1279 | void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { |
| 1280 | if (k->k == VKSTR) |
| 1281 | str2K(fs, k); |
| 1282 | lua_assert(!hasjumps(t) && |
| 1283 | (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL)); |
| 1284 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ |
| 1285 | luaK_exp2anyreg(fs, t); /* put it in a register */ |
| 1286 | if (t->k == VUPVAL) { |
| 1287 | int temp = t->u.info; /* upvalue index */ |
| 1288 | lua_assert(isKstr(fs, k)); |
| 1289 | t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ |
| 1290 | t->u.ind.idx = k->u.info; /* literal short string */ |
| 1291 | t->k = VINDEXUP; |
| 1292 | } |
| 1293 | else { |
| 1294 | /* register index of the table */ |
| 1295 | t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info; |
| 1296 | if (isKstr(fs, k)) { |
| 1297 | t->u.ind.idx = k->u.info; /* literal short string */ |
| 1298 | t->k = VINDEXSTR; |
| 1299 | } |
| 1300 | else if (isCint(k)) { |
| 1301 | t->u.ind.idx = cast_int(k->u.ival); /* int. constant in proper range */ |
| 1302 | t->k = VINDEXI; |
| 1303 | } |
| 1304 | else { |
| 1305 | t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */ |
| 1306 | t->k = VINDEXED; |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | /* |
no test coverage detected