ltable.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. ** $Id: ltable.h,v 2.20 2014/09/04 18:15:29 roberto Exp roberto $
  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. /* returns the key, given the value of a table entry */
  21. #define keyfromval(v) \
  22. (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
  23. LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
  24. LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
  25. TValue *value);
  26. LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
  27. LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
  28. LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
  29. LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
  30. LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
  31. LUAI_FUNC Table *luaH_new (lua_State *L);
  32. LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
  33. unsigned int nhsize);
  34. LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
  35. LUAI_FUNC void luaH_free (lua_State *L, Table *t);
  36. LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
  37. LUAI_FUNC int luaH_getn (Table *t);
  38. #if defined(LUA_DEBUG)
  39. LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
  40. LUAI_FUNC int luaH_isdummy (Node *n);
  41. #endif
  42. #endif