| 287 | |
| 288 | |
| 289 | static int addk (FuncState *fs, TValue *key, TValue *v) { |
| 290 | lua_State *L = fs->ls->L; |
| 291 | TValue *idx = luaH_set(L, fs->h, key); |
| 292 | Proto *f = fs->f; |
| 293 | int k, oldsize; |
| 294 | if (ttisnumber(idx)) { |
| 295 | lua_Number n = nvalue(idx); |
| 296 | lua_number2int(k, n); |
| 297 | if (luaV_rawequalobj(&f->k[k], v)) |
| 298 | return k; |
| 299 | /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); |
| 300 | go through and create a new entry for this value */ |
| 301 | } |
| 302 | /* constant not found; create a new entry */ |
| 303 | oldsize = f->sizek; |
| 304 | k = fs->nk; |
| 305 | /* numerical value does not need GC barrier; |
| 306 | table has no metatable, so it does not need to invalidate cache */ |
| 307 | setnvalue(idx, cast_num(k)); |
| 308 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); |
| 309 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
| 310 | setobj(L, &f->k[k], v); |
| 311 | fs->nk++; |
| 312 | luaC_barrier(L, f, v); |
| 313 | return k; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | int luaK_stringK (FuncState *fs, TString *s) { |
no test coverage detected