1 /* $NetBSD: ltable.h,v 1.7 2017/04/26 13:17:33 mbalmer Exp $ */ 2 3 /* 4 ** Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp 5 ** Lua tables (hash) 6 ** See Copyright Notice in lua.h 7 */ 8 9 #ifndef ltable_h 10 #define ltable_h 11 12 #include "lobject.h" 13 14 15 #define gnode(t,i) (&(t)->node[i]) 16 #define gval(n) (&(n)->i_val) 17 #define gnext(n) ((n)->i_key.nk.next) 18 19 20 /* 'const' to avoid wrong writings that can mess up field 'next' */ 21 #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 22 23 /* 24 ** writable version of 'gkey'; allows updates to individual fields, 25 ** but not to the whole (which has incompatible type) 26 */ 27 #define wgkey(n) (&(n)->i_key.nk) 28 29 #define invalidateTMcache(t) ((t)->flags = 0) 30 31 32 /* true when 't' is using 'dummynode' as its hash part */ 33 #define isdummy(t) ((t)->lastfree == NULL) 34 35 36 /* allocated size for hash nodes */ 37 #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 38 39 40 /* returns the key, given the value of a table entry */ 41 #define keyfromval(v) \ 42 (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 43 44 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 TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 52 LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 53 LUAI_FUNC Table *luaH_new (lua_State *L); 54 LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 55 unsigned int nhsize); 56 LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 57 LUAI_FUNC void luaH_free (lua_State *L, Table *t); 58 LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 59 LUAI_FUNC int luaH_getn (Table *t); 60 61 62 #if defined(LUA_DEBUG) 63 LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 64 LUAI_FUNC int luaH_isdummy (const Table *t); 65 #endif 66 67 68 #endif 69