MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / addk

Function addk

libraries/AP_Scripting/lua/src/lcode.c:435–459  ·  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

433** keys), the caller must provide a useful 'key' for indexing the cache.
434*/
435static int addk (FuncState *fs, TValue *key, TValue *v) {
436 lua_State *L = fs->ls->L;
437 Proto *f = fs->f;
438 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */
439 int k, oldsize;
440 if (ttisinteger(idx)) { /* is there an index there? */
441 k = cast_int(ivalue(idx));
442 /* correct value? (warning: must distinguish floats from integers!) */
443 if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&
444 luaV_rawequalobj(&f->k[k], v))
445 return k; /* reuse index */
446 }
447 /* constant not found; create a new entry */
448 oldsize = f->sizek;
449 k = fs->nk;
450 /* numerical value does not need GC barrier;
451 table has no metatable, so it does not need to invalidate cache */
452 setivalue(idx, k);
453 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
454 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
455 setobj(L, &f->k[k], v);
456 fs->nk++;
457 luaC_barrier(L, f, v);
458 return k;
459}
460
461
462/*

Callers 5

luaK_stringKFunction · 0.85
luaK_intKFunction · 0.85
luaK_numberKFunction · 0.85
boolKFunction · 0.85
nilKFunction · 0.85

Calls 1

luaH_setFunction · 0.85

Tested by

no test coverage detected