ltable.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. ** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 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. /* test Table to determine if it is a RW or RO table */
  28. #define isrotable(t) (gettt(t)==LUA_TTBLROF)
  29. #define isrwtable(t) (gettt(t)==LUA_TTBLRAM)
  30. LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
  31. LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
  32. TValue *value);
  33. LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
  34. LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
  35. LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
  36. LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
  37. LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
  38. LUAI_FUNC Table *luaH_new (lua_State *L);
  39. LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
  40. unsigned int nhsize);
  41. LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
  42. LUAI_FUNC void luaH_free (lua_State *L, Table *t);
  43. LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
  44. LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
  45. #if defined(LUA_DEBUG)
  46. LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
  47. LUAI_FUNC int luaH_isdummy (const Table *t);
  48. #endif
  49. #endif