MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / addk

Function addk

lib/lua/src/lcode.c:543–569  ·  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

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

Callers 6

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

Calls 2

luaH_getFunction · 0.85
luaH_finishsetFunction · 0.85

Tested by

no test coverage detected