ltable.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. ** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $
  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)->i_key.nk.next)
  12. /* 'const' to avoid wrong writings that can mess up field 'next' */
  13. #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk))
  14. /*
  15. ** writable version of 'gkey'; allows updates to individual fields,
  16. ** but not to the whole (which has incompatible type)
  17. */
  18. #define wgkey(n) (&(n)->i_key.nk)
  19. #define invalidateTMcache(t) ((t)->flags = 0)
  20. /* true when 't' is using 'dummynode' as its hash part */
  21. #define isdummy(t) ((t)->lastfree == NULL)
  22. /* allocated size for hash nodes */
  23. #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t))
  24. /* returns the key, given the value of a table entry */
  25. #define keyfromval(v) \
  26. (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
  27. LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
  28. LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
  29. TValue *value);
  30. LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
  31. LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
  32. LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
  33. LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
  34. LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
  35. LUAI_FUNC Table *luaH_new (lua_State *L);
  36. LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
  37. unsigned int nhsize);
  38. LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
  39. LUAI_FUNC void luaH_free (lua_State *L, Table *t);
  40. LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
  41. LUAI_FUNC int luaH_getn (Table *t);
  42. #if defined(LUA_DEBUG)
  43. LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
  44. LUAI_FUNC int luaH_isdummy (const Table *t);
  45. #endif
  46. #endif