CHDK_DE Vorschauversion  Trunk Rev. 5232
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
ltable.h-Dateireferenz
#include "lobject.h"
+ Include-Abhängigkeitsdiagramm für ltable.h:
+ Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#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)
 

Funktionen

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)
 

Makro-Dokumentation

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

Definiert in Zeile 14 der Datei ltable.h.

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

Definiert in Zeile 16 der Datei ltable.h.

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

Definiert in Zeile 13 der Datei ltable.h.

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

Definiert in Zeile 15 der Datei ltable.h.

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

Definiert in Zeile 18 der Datei ltable.h.

Dokumentation der Funktionen

LUAI_FUNC void luaH_free ( lua_State L,
Table t 
)

Definiert in Zeile 374 der Datei ltable.c.

374  {
375  if (t->node != dummynode)
376  luaM_freearray(L, t->node, sizenode(t), Node);
377  luaM_freearray(L, t->array, t->sizearray, TValue);
378  luaM_free(L, t);
379 }
LUAI_FUNC const TValue* luaH_get ( Table t,
const TValue key 
)

Definiert in Zeile 469 der Datei 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 }
LUAI_FUNC int luaH_getn ( Table t)

Definiert in Zeile 560 der Datei 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 }
LUAI_FUNC const TValue* luaH_getnum ( Table t,
int  key 
)

Definiert in Zeile 435 der Datei 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 {
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 }
LUAI_FUNC const TValue* luaH_getstr ( Table t,
TString key 
)

Definiert in Zeile 455 der Datei 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 }
LUAI_FUNC Table* luaH_new ( lua_State L,
int  narray,
int  lnhash 
)

Definiert in Zeile 358 der Datei ltable.c.

358  {
359  Table *t = luaM_new(L, Table);
360  luaC_link(L, obj2gco(t), LUA_TTABLE);
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 }
LUAI_FUNC int luaH_next ( lua_State L,
Table t,
StkId  key 
)

Definiert in Zeile 162 der Datei 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 }
LUAI_FUNC void luaH_resizearray ( lua_State L,
Table t,
int  nasize 
)

Definiert in Zeile 327 der Datei ltable.c.

327  {
328  int nsize = (t->node == dummynode) ? 0 : sizenode(t);
329  resize(L, t, nasize, nsize);
330 }
LUAI_FUNC TValue* luaH_set ( lua_State L,
Table t,
const TValue key 
)

Definiert in Zeile 494 der Datei 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 }
LUAI_FUNC TValue* luaH_setnum ( lua_State L,
Table t,
int  key 
)

Definiert in Zeile 508 der Datei 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 }
LUAI_FUNC TValue* luaH_setstr ( lua_State L,
Table t,
TString key 
)

Definiert in Zeile 520 der Datei 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 }