Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ltable.h File Reference
#include "lobject.h"

Go to the source code of this file.

Macros

#define gnode(t, i)   (&(t)->node[i])
 
#define gval(n)   (&(n)->i_val)
 
#define gnext(n)   ((n)->i_key.nk.next)
 
#define gkey(n)   cast(const TValue*, (&(n)->i_key.tvk))
 
#define wgkey(n)   (&(n)->i_key.nk)
 
#define invalidateTMcache(t)   ((t)->flags = 0)
 
#define isdummy(t)   ((t)->lastfree == NULL)
 
#define allocsizenode(t)   (isdummy(t) ? 0 : sizenode(t))
 
#define keyfromval(v)    (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
 

Functions

LUAI_FUNC const TValueluaH_getint (Table *t, lua_Integer key)
 
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value)
 
LUAI_FUNC const TValueluaH_getshortstr (Table *t, TString *key)
 
LUAI_FUNC const TValueluaH_getstr (Table *t, TString *key)
 
LUAI_FUNC const TValueluaH_get (Table *t, const TValue *key)
 
LUAI_FUNC TValueluaH_newkey (lua_State *L, Table *t, const TValue *key)
 
LUAI_FUNC TValueluaH_set (lua_State *L, Table *t, const TValue *key)
 
LUAI_FUNC TableluaH_new (lua_State *L)
 
LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize)
 
LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize)
 
LUAI_FUNC void luaH_free (lua_State *L, Table *t)
 
LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key)
 
LUAI_FUNC lua_Unsigned luaH_getn (Table *t)
 

Macro Definition Documentation

◆ allocsizenode

#define allocsizenode ( t)    (isdummy(t) ? 0 : sizenode(t))

Definition at line 35 of file lua-5.3.6/src/ltable.h.

Referenced by luaH_resize(), luaH_resizearray(), traversetable(), and traversetable().

◆ gkey

#define gkey ( n)    cast(const TValue*, (&(n)->i_key.tvk))

Definition at line 19 of file lua-5.3.6/src/ltable.h.

◆ gnext

#define gnext ( n)    ((n)->i_key.nk.next)

Definition at line 15 of file lua-5.3.6/src/ltable.h.

◆ gnode

#define gnode ( t,
i )   (&(t)->node[i])

Definition at line 13 of file lua-5.3.6/src/ltable.h.

◆ gval

#define gval ( n)    (&(n)->i_val)

Definition at line 14 of file lua-5.3.6/src/ltable.h.

◆ invalidateTMcache

#define invalidateTMcache ( t)    ((t)->flags = 0)

Definition at line 27 of file lua-5.3.6/src/ltable.h.

◆ isdummy

#define isdummy ( t)    ((t)->lastfree == NULL)

Definition at line 31 of file lua-5.3.6/src/ltable.h.

◆ keyfromval

#define keyfromval ( v)     (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))

Definition at line 39 of file lua-5.3.6/src/ltable.h.

39#define keyfromval(v) \
40 (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))

◆ wgkey

#define wgkey ( n)    (&(n)->i_key.nk)

Definition at line 25 of file lua-5.3.6/src/ltable.h.

Referenced by removeentry(), and setnodevector().

Function Documentation

◆ luaH_free()

LUAI_FUNC void luaH_free ( lua_State * L,
Table * t )

Definition at line 374 of file lua-5.1.5/src/ltable.c.

374 {
375 if (t->node != dummynode)
376 luaM_freearray(L, t->node, sizenode(t), Node);
378 luaM_free(L, t);
379}
#define luaM_freearray(L, b, n, t)
#define luaM_free(L, b)
#define sizenode(t)
#define dummynode

◆ luaH_get()

LUAI_FUNC const TValue * luaH_get ( Table * t,
const TValue * key )

Definition at line 469 of file lua-5.1.5/src/ltable.c.

469 {
470 switch (ttype(key)) {
471 case LUA_TNIL: return luaO_nilobject;
472 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
473 case LUA_TNUMBER: {
474 int k;
475 lua_Number n = nvalue(key);
476 lua_number2int(k, n);
477 if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
478 return luaH_getnum(t, k); /* use specialized version */
479 /* else go through */
480 }
481 default: {
482 Node *n = mainposition(t, key);
483 do { /* check whether `key' is somewhere in the chain */
484 if (luaO_rawequalObj(key2tval(n), key))
485 return gval(n); /* that's it */
486 else n = gnext(n);
487 } while (n);
488 return luaO_nilobject;
489 }
490 }
491}
#define cast_num(i)
int luaO_rawequalObj(const TValue *t1, const TValue *t2)
#define nvalue(o)
#define luaO_nilobject
#define rawtsvalue(o)
#define ttype(o)
const TValue * luaH_getnum(Table *t, int key)
const TValue * luaH_getstr(Table *t, TString *key)
static Node * mainposition(const Table *t, const TValue *key)
#define gnext(n)
#define gval(n)
#define key2tval(n)
#define LUA_TSTRING
#define LUA_TNUMBER
#define LUA_TNIL
LUA_NUMBER lua_Number
#define lua_number2int(i, d)
#define luai_numeq(a, b)

◆ luaH_getint()

LUAI_FUNC const TValue * luaH_getint ( Table * t,
lua_Integer key )

Definition at line 516 of file lua-5.3.6/src/ltable.c.

516 {
517 /* (1 <= key && key <= t->sizearray) */
518 if (l_castS2U(key) - 1 < t->sizearray)
519 return &t->array[key - 1];
520 else {
521 Node *n = hashint(t, key);
522 for (;;) { /* check whether 'key' is somewhere in the chain */
523 if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)
524 return gval(n); /* that's it */
525 else {
526 int nx = gnext(n);
527 if (nx == 0) break;
528 n += nx;
529 }
530 }
531 return luaO_nilobject;
532 }
533}
#define gkey(n)
#define l_castS2U(i)
#define ttisinteger(o)
#define ivalue(o)
#define hashint(t, i)

◆ luaH_getn()

LUAI_FUNC lua_Unsigned luaH_getn ( Table * t)

Definition at line 560 of file lua-5.1.5/src/ltable.c.

560 {
561 unsigned int j = t->sizearray;
562 if (j > 0 && ttisnil(&t->array[j - 1])) {
563 /* there is a boundary in the array part: (binary) search for it */
564 unsigned int i = 0;
565 while (j - i > 1) {
566 unsigned int m = (i+j)/2;
567 if (ttisnil(&t->array[m - 1])) j = m;
568 else i = m;
569 }
570 return i;
571 }
572 /* else must find a boundary in hash part */
573 else if (t->node == dummynode) /* hash part is empty? */
574 return j; /* that is easy... */
575 else return unbound_search(t, j);
576}
#define ttisnil(o)
static int unbound_search(Table *t, unsigned int j)

◆ luaH_getshortstr()

LUAI_FUNC const TValue * luaH_getshortstr ( Table * t,
TString * key )

Definition at line 539 of file lua-5.3.6/src/ltable.c.

539 {
540 Node *n = hashstr(t, key);
541 lua_assert(key->tt == LUA_TSHRSTR);
542 for (;;) { /* check whether 'key' is somewhere in the chain */
543 const TValue *k = gkey(n);
544 if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))
545 return gval(n); /* that's it */
546 else {
547 int nx = gnext(n);
548 if (nx == 0)
549 return luaO_nilobject; /* not found */
550 n += nx;
551 }
552 }
553}
#define lua_assert(c)
#define tsvalue(o)
#define LUA_TSHRSTR
#define ttisshrstring(o)
#define eqshrstr(a, b)
#define hashstr(t, str)

◆ luaH_getstr()

LUAI_FUNC const TValue * luaH_getstr ( Table * t,
TString * key )

Definition at line 455 of file lua-5.1.5/src/ltable.c.

455 {
456 Node *n = hashstr(t, key);
457 do { /* check whether `key' is somewhere in the chain */
458 if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
459 return gval(n); /* that's it */
460 else n = gnext(n);
461 } while (n);
462 return luaO_nilobject;
463}
#define ttisstring(o)
#define hashstr(t, str)

◆ luaH_new()

LUAI_FUNC Table * luaH_new ( lua_State * L)

Definition at line 368 of file lua-5.2.4/src/ltable.c.

368 {
369 Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
370 t->metatable = NULL;
371 t->flags = cast_byte(~0);
372 t->array = NULL;
373 t->sizearray = 0;
374 setnodevector(L, t, 0);
375 return t;
376}
#define NULL
Definition gmacros.h:924
#define cast_byte(i)
#define LUA_TTABLE
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
static void setnodevector(lua_State *L, Table *t, int size)
struct Table * metatable
struct Table h

◆ luaH_newkey()

LUAI_FUNC TValue * luaH_newkey ( lua_State * L,
Table * t,
const TValue * key )

Definition at line 405 of file lua-5.2.4/src/ltable.c.

405 {
406 Node *mp;
407 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
408 else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
409 luaG_runerror(L, "table index is NaN");
410 mp = mainposition(t, key);
411 if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
412 Node *othern;
413 Node *n = getfreepos(t); /* get a free place */
414 if (n == NULL) { /* cannot find a free place? */
415 rehash(L, t, key); /* grow table */
416 /* whatever called 'newkey' take care of TM cache and GC barrier */
417 return luaH_set(L, t, key); /* insert key into grown table */
418 }
419 lua_assert(!isdummy(n));
420 othern = mainposition(t, gkey(mp));
421 if (othern != mp) { /* is colliding node out of its main position? */
422 /* yes; move colliding node into free position */
423 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
424 gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
425 *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
426 gnext(mp) = NULL; /* now `mp' is free */
427 setnilvalue(gval(mp));
428 }
429 else { /* colliding node is in its own main position */
430 /* new node will go into free position */
431 gnext(n) = gnext(mp); /* chain new position */
432 gnext(mp) = n;
433 mp = n;
434 }
435 }
436 setobj2t(L, gkey(mp), key);
437 luaC_barrierback(L, obj2gco(t), key);
438 lua_assert(ttisnil(gval(mp)));
439 return gval(mp);
440}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define ttisnumber(o)
#define setnilvalue(obj)
#define setobj2t
#define obj2gco(v)
#define luaC_barrierback(L, p, v)
static Node * getfreepos(Table *t)
#define isdummy(n)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
static Node * mainposition(const Table *t, const TValue *key)
static void rehash(lua_State *L, Table *t, const TValue *ek)
#define luai_numisnan(a)

References cast_int, fltvalue, getfreepos(), getfreepos(), gkey, gnext, gval, Node::i_key, isdummy, lua_assert, luaC_barrierback, luaG_runerror(), luaH_set(), luai_numisnan, luaV_tointeger(), mainposition(), mainposition(), NULL, nvalue, obj2gco, rehash(), rehash(), setivalue, setnilvalue, setnodekey, setobj2t, ttisfloat, ttisnil, and ttisnumber.

Referenced by luaH_set(), luaH_setint(), luaH_setint(), luaV_finishset(), and luaV_settable().

◆ luaH_next()

LUAI_FUNC int luaH_next ( lua_State * L,
Table * t,
StkId key )

Definition at line 162 of file lua-5.1.5/src/ltable.c.

162 {
163 int i = findindex(L, t, key); /* find original element */
164 for (i++; i < t->sizearray; i++) { /* try first array part */
165 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
166 setnvalue(key, cast_num(i+1));
167 setobj2s(L, key+1, &t->array[i]);
168 return 1;
169 }
170 }
171 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
172 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
173 setobj2s(L, key, key2tval(gnode(t, i)));
174 setobj2s(L, key+1, gval(gnode(t, i)));
175 return 1;
176 }
177 }
178 return 0; /* no more elements */
179}
#define setobj2s
#define setnvalue(obj, x)
static int findindex(lua_State *L, Table *t, StkId key)
#define gnode(t, i)

◆ luaH_resize()

LUAI_FUNC void luaH_resize ( lua_State * L,
Table * t,
unsigned int nasize,
unsigned int nhsize )

Definition at line 347 of file lua-5.3.6/src/ltable.c.

348 {
349 unsigned int i;
350 int j;
351 AuxsetnodeT asn;
352 unsigned int oldasize = t->sizearray;
353 int oldhsize = allocsizenode(t);
354 Node *nold = t->node; /* save old hash ... */
355 if (nasize > oldasize) /* array part must grow? */
356 setarrayvector(L, t, nasize);
357 /* create new hash part with appropriate size */
358 asn.t = t; asn.nhsize = nhsize;
359 if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */
360 setarrayvector(L, t, oldasize); /* array back to its original size */
361 luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */
362 }
363 if (nasize < oldasize) { /* array part must shrink? */
364 t->sizearray = nasize;
365 /* re-insert elements from vanishing slice */
366 for (i=nasize; i<oldasize; i++) {
367 if (!ttisnil(&t->array[i]))
368 luaH_setint(L, t, i + 1, &t->array[i]);
369 }
370 /* shrink array */
371 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
372 }
373 /* re-insert elements from hash part */
374 for (j = oldhsize - 1; j >= 0; j--) {
375 Node *old = nold + j;
376 if (!ttisnil(gval(old))) {
377 /* doesn't need barrier/invalidate cache, as entry was
378 already present in the table */
379 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
380 }
381 }
382 if (oldhsize > 0) /* not the dummy node? */
383 luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */
384}
void luaD_throw(lua_State *L, int errcode)
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
#define cast(t, exp)
#define luaM_reallocvector(L, v, oldn, n, t)
#define setobjt2t
#define LUA_ERRMEM
#define LUA_OK
static void setarrayvector(lua_State *L, Table *t, unsigned int size)
void luaH_setint(lua_State *L, Table *t, lua_Integer key, TValue *value)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
static void auxsetnode(lua_State *L, void *ud)
#define allocsizenode(t)
unsigned int nhsize

◆ luaH_resizearray()

LUAI_FUNC void luaH_resizearray ( lua_State * L,
Table * t,
unsigned int nasize )

Definition at line 387 of file lua-5.3.6/src/ltable.c.

387 {
388 int nsize = allocsizenode(t);
389 luaH_resize(L, t, nasize, nsize);
390}
void luaH_resize(lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize)

◆ luaH_set()

LUAI_FUNC TValue * luaH_set ( lua_State * L,
Table * t,
const TValue * key )

Definition at line 494 of file lua-5.1.5/src/ltable.c.

494 {
495 const TValue *p = luaH_get(t, key);
496 t->flags = 0;
497 if (p != luaO_nilobject)
498 return cast(TValue *, p);
499 else {
500 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
501 else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
502 luaG_runerror(L, "table index is NaN");
503 return newkey(L, t, key);
504 }
505}
const TValue * luaH_get(Table *t, const TValue *key)
static TValue * newkey(lua_State *L, Table *t, const TValue *key)

References cast, Table::flags, luaG_runerror(), luaH_get(), luaH_newkey(), luai_numisnan, luaO_nilobject, newkey(), nvalue, ttisnil, and ttisnumber.

Referenced by addk(), addk(), addk(), aux_rawset(), lua_rawset(), lua_rawsetp(), luaH_newkey(), luaH_resize(), luaH_resize(), luaV_settable(), luaX_newstring(), newkey(), and resize().

◆ luaH_setint()

LUAI_FUNC void luaH_setint ( lua_State * L,
Table * t,
lua_Integer key,
TValue * value )

Definition at line 618 of file lua-5.3.6/src/ltable.c.

618 {
619 const TValue *p = luaH_getint(t, key);
620 TValue *cell;
621 if (p != luaO_nilobject)
622 cell = cast(TValue *, p);
623 else {
624 TValue k;
625 setivalue(&k, key);
626 cell = luaH_newkey(L, t, &k);
627 }
628 setobj2t(L, cell, value);
629}
int value
Definition lsqlite3.c:2155
#define setivalue(obj, x)
TValue * luaH_newkey(lua_State *L, Table *t, const TValue *key)
const TValue * luaH_getint(Table *t, lua_Integer key)