MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / addk

Function addk

third-party/lua-5.4.6/src/lcode.c:544–570  ·  view source on GitHub ↗

** Add constant 'v' to prototype's list of constants (field 'k'). ** Use scanner's table to cache position of constants in constant list ** and try to reuse constants. Because some values should not be used ** as keys (nil cannot be a key, integer keys can collapse with float ** keys), the caller must provide a useful 'key' for indexing the cache. ** Note that all functions share the same table, s

Source from the content-addressed store, hash-verified

542** a function can make some indices wrong.
543*/
544static int addk (FuncState *fs, TValue *key, TValue *v) {
545 TValue val;
546 lua_State *L = fs->ls->L;
547 Proto *f = fs->f;
548 const TValue *idx = luaH_get(fs->ls->h, key); /* query scanner table */
549 int k, oldsize;
550 if (ttisinteger(idx)) { /* is there an index there? */
551 k = cast_int(ivalue(idx));
552 /* correct value? (warning: must distinguish floats from integers!) */
553 if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&
554 luaV_rawequalobj(&f->k[k], v))
555 return k; /* reuse index */
556 }
557 /* constant not found; create a new entry */
558 oldsize = f->sizek;
559 k = fs->nk;
560 /* numerical value does not need GC barrier;
561 table has no metatable, so it does not need to invalidate cache */
562 setivalue(&val, k);
563 luaH_finishset(L, fs->ls->h, key, idx, &val);
564 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
565 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
566 setobj(L, &f->k[k], v);
567 fs->nk++;
568 luaC_barrier(L, f, v);
569 return k;
570}
571
572
573/*

Callers 6

stringKFunction · 0.70
luaK_intKFunction · 0.70
luaK_numberKFunction · 0.70
boolFFunction · 0.70
boolTFunction · 0.70
nilKFunction · 0.70

Calls 2

luaH_getFunction · 0.70
luaH_finishsetFunction · 0.70

Tested by

no test coverage detected