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 gkey(n)   (&(n)->i_key.nk)
 
#define gval(n)   (&(n)->i_val)
 
#define gnext(n)   ((n)->i_key.nk.next)
 
#define key2tval(n)   (&(n)->i_key.tvk)
 

Functions

LUAI_FUNC const TValueluaH_getnum (Table *t, int key)
 
LUAI_FUNC TValueluaH_setnum (lua_State *L, Table *t, int key)
 
LUAI_FUNC const TValueluaH_getstr (Table *t, TString *key)
 
LUAI_FUNC TValueluaH_setstr (lua_State *L, Table *t, TString *key)
 
LUAI_FUNC const TValueluaH_get (Table *t, const TValue *key)
 
LUAI_FUNC TValueluaH_set (lua_State *L, Table *t, const TValue *key)
 
LUAI_FUNC TableluaH_new (lua_State *L, int narray, int lnhash)
 
LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, 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 int luaH_getn (Table *t)
 

Macro Definition Documentation

◆ gkey

◆ gnext

◆ gnode

◆ gval

◆ key2tval

#define key2tval ( n)    (&(n)->i_key.tvk)

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_getn()

LUAI_FUNC int 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_getnum()

LUAI_FUNC const TValue * luaH_getnum ( Table * t,
int key )

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

435 {
436 /* (1 <= key && key <= t->sizearray) */
437 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
438 return &t->array[key-1];
439 else {
440 lua_Number nk = cast_num(key);
441 Node *n = hashnum(t, nk);
442 do { /* check whether `key' is somewhere in the chain */
443 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
444 return gval(n); /* that's it */
445 else n = gnext(n);
446 } while (n);
447 return luaO_nilobject;
448 }
449}
#define cast(t, exp)
#define ttisnumber(o)
static Node * hashnum(const Table *t, lua_Number n)
#define gkey(n)

References Table::array, cast, cast_num, gkey, gnext, gval, hashnum(), luai_numeq, luaO_nilobject, nvalue, Table::sizearray, and ttisnumber.

Referenced by lua_rawgeti(), luaH_get(), luaH_setnum(), and unbound_search().

◆ 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,
int narray,
int lnhash )

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

358 {
359 Table *t = luaM_new(L, Table);
361 t->metatable = NULL;
362 t->flags = cast_byte(~0);
363 /* temporary values (kept only if some malloc fails) */
364 t->array = NULL;
365 t->sizearray = 0;
366 t->lsizenode = 0;
367 t->node = cast(Node *, dummynode);
368 setarrayvector(L, t, narray);
369 setnodevector(L, t, nhash);
370 return t;
371}
#define NULL
Definition gmacros.h:924
void luaC_link(lua_State *L, GCObject *o, lu_byte tt)
#define cast_byte(i)
#define luaM_new(L, t)
#define obj2gco(v)
static void setarrayvector(lua_State *L, Table *t, int size)
static void setnodevector(lua_State *L, Table *t, int size)
#define LUA_TTABLE
struct Table * metatable

References Table::array, cast, cast_byte, dummynode, Table::flags, Table::lsizenode, LUA_TTABLE, luaC_link(), luaM_new, Table::metatable, Table::node, NULL, obj2gco, setarrayvector(), setnodevector(), and Table::sizearray.

Referenced by adjust_varargs(), collectvalidlines(), collectvalidlines(), collectvalidlines(), collectvalidlines(), f_luaopen(), init_registry(), init_registry(), init_registry(), lua_createtable(), luaV_execute(), luaV_execute(), luaV_execute(), luaY_parser(), open_func(), and open_func().

◆ 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_resizearray()

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

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

327 {
328 int nsize = (t->node == dummynode) ? 0 : sizenode(t);
329 resize(L, t, nasize, nsize);
330}
static void resize(lua_State *L, Table *t, int nasize, 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}
void luaG_runerror(lua_State *L, const char *fmt,...)
const TValue * luaH_get(Table *t, const TValue *key)
static TValue * newkey(lua_State *L, Table *t, const TValue *key)
#define luai_numisnan(a)

◆ luaH_setnum()

LUAI_FUNC TValue * luaH_setnum ( lua_State * L,
Table * t,
int key )

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

508 {
509 const TValue *p = luaH_getnum(t, key);
510 if (p != luaO_nilobject)
511 return cast(TValue *, p);
512 else {
513 TValue k;
514 setnvalue(&k, cast_num(key));
515 return newkey(L, t, &k);
516 }
517}

References cast, cast_num, luaH_getnum(), luaO_nilobject, newkey(), and setnvalue.

Referenced by adjust_varargs(), collectvalidlines(), lua_rawseti(), luaV_execute(), and resize().

◆ luaH_setstr()

LUAI_FUNC TValue * luaH_setstr ( lua_State * L,
Table * t,
TString * key )

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

520 {
521 const TValue *p = luaH_getstr(t, key);
522 if (p != luaO_nilobject)
523 return cast(TValue *, p);
524 else {
525 TValue k;
526 setsvalue(L, &k, key);
527 return newkey(L, t, &k);
528 }
529}
#define setsvalue(L, obj, x)

References cast, luaH_getstr(), luaO_nilobject, newkey(), and setsvalue.

Referenced by adjust_varargs(), and luaX_newstring().