xref: /netbsd-src/external/mit/lua/dist/src/ltable.h (revision 212397c69a103ae7e5eafa8731ddfae671d2dee7)
1 /*	$NetBSD: ltable.h,v 1.4 2016/01/28 14:41:39 lneto Exp $	*/
2 
3 /*
4 ** Id: ltable.h,v 2.21 2015/11/03 15:47:30 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 /* returns the key, given the value of a table entry */
33 #define keyfromval(v) \
34   (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
35 
36 
37 LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
38 LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
39                                                     TValue *value);
40 LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
41 LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
42 LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
43 LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
44 LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
45 LUAI_FUNC Table *luaH_new (lua_State *L);
46 LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
47                                                     unsigned int nhsize);
48 LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
49 LUAI_FUNC void luaH_free (lua_State *L, Table *t);
50 LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
51 LUAI_FUNC int luaH_getn (Table *t);
52 
53 
54 #if defined(LUA_DEBUG)
55 LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
56 LUAI_FUNC int luaH_isdummy (Node *n);
57 #endif
58 
59 
60 #endif
61