MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / addk

Function addk

extlibs/lua/src/lcode.c:549–573  ·  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. */

Source from the content-addressed store, hash-verified

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

Callers 6

stringKFunction · 0.85
luaK_intKFunction · 0.85
luaK_numberKFunction · 0.85
boolFFunction · 0.85
boolTFunction · 0.85
nilKFunction · 0.85

Calls 1

luaH_setFunction · 0.85

Tested by

no test coverage detected