ltable.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ** $Id: ltable.h $
  3. ** Lua tables (hash)
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef ltable_h
  7. #define ltable_h
  8. #include "lobject.h"
  9. #define gnode(t,i) (&(t)->node[i])
  10. #define gval(n) (&(n)->i_val)
  11. #define gnext(n) ((n)->u.next)
  12. /*
  13. ** Clear all bits of fast-access metamethods, which means that the table
  14. ** may have any of these metamethods. (First access that fails after the
  15. ** clearing will set the bit again.)
  16. */
  17. #define invalidateTMcache(t) ((t)->flags &= ~maskflags)
  18. /* true when 't' is using 'dummynode' as its hash part */
  19. #define isdummy(t) ((t)->lastfree == NULL)
  20. /* allocated size for hash nodes */
  21. #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t))
  22. /* returns the Node, given the value of a table entry */
  23. #define nodefromval(v) cast(Node *, (v))
  24. /* results from get/set */
  25. #define HOK 0
  26. #define HNOTFOUND 1
  27. #define HNOTATABLE 2
  28. #define HFIRSTNODE 3
  29. /* fast access to components of array values */
  30. #define getArrTag(t,k) (&(t)->array[k - 1].tt_)
  31. #define getArrVal(t,k) (&(t)->array[k - 1].value_)
  32. #define tagisempty(tag) (novariant(tag) == LUA_TNIL)
  33. #define arr2val(h,k,tag,res) \
  34. ((res)->tt_ = tag, (res)->value_ = *getArrVal(h,k))
  35. #define val2arr(h,k,tag,val) \
  36. (*tag = (val)->tt_, *getArrVal(h,k) = (val)->value_)
  37. LUAI_FUNC int luaH_getshortstr1 (Table *t, TString *key, TValue *res);
  38. LUAI_FUNC int luaH_getstr1 (Table *t, TString *key, TValue *res);
  39. LUAI_FUNC int luaH_get1 (Table *t, const TValue *key, TValue *res);
  40. LUAI_FUNC int luaH_getint1 (Table *t, lua_Integer key, TValue *res);
  41. LUAI_FUNC int luaH_setint1 (Table *t, lua_Integer key, TValue *val);
  42. LUAI_FUNC int luaH_setshortstr1 (Table *t, TString *key, TValue *val);
  43. LUAI_FUNC int luaH_setstr1 (Table *t, TString *key, TValue *val);
  44. LUAI_FUNC int luaH_set1 (Table *t, const TValue *key, TValue *val);
  45. LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
  46. LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
  47. TValue *value);
  48. LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
  49. LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
  50. LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
  51. LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key,
  52. TValue *value);
  53. LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key,
  54. TValue *value);
  55. LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key,
  56. const TValue *slot, TValue *value);
  57. LUAI_FUNC void luaH_finishset1 (lua_State *L, Table *t, const TValue *key,
  58. TValue *value, int aux);
  59. LUAI_FUNC Table *luaH_new (lua_State *L);
  60. LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
  61. unsigned int nhsize);
  62. LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
  63. LUAI_FUNC void luaH_free (lua_State *L, Table *t);
  64. LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
  65. LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
  66. LUAI_FUNC unsigned int luaH_realasize (const Table *t);
  67. #if defined(LUA_DEBUG)
  68. LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
  69. #endif
  70. #endif