xref: /minix/external/mit/lua/dist/src/ltable.h (revision 0a6a1f1d)
1 /*
2 ** $Id: ltable.h,v 1.3 2015/02/02 14:03:05 lneto Exp $
3 ** Lua tables (hash)
4 ** See Copyright Notice in lua.h
5 */
6 
7 #ifndef ltable_h
8 #define ltable_h
9 
10 #include "lobject.h"
11 
12 
13 #define gnode(t,i)	(&(t)->node[i])
14 #define gval(n)		(&(n)->i_val)
15 #define gnext(n)	((n)->i_key.nk.next)
16 
17 
18 /* 'const' to avoid wrong writings that can mess up field 'next' */
19 #define gkey(n)		cast(const TValue*, (&(n)->i_key.tvk))
20 
21 #define wgkey(n)		(&(n)->i_key.nk)
22 
23 #define invalidateTMcache(t)	((t)->flags = 0)
24 
25 
26 /* returns the key, given the value of a table entry */
27 #define keyfromval(v) \
28   (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
29 
30 
31 LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
32 LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
33                                                     TValue *value);
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 int luaH_getn (Table *t);
45 
46 
47 #if defined(LUA_DEBUG)
48 LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
49 LUAI_FUNC int luaH_isdummy (Node *n);
50 #endif
51 
52 
53 #endif
54