summaryrefslogtreecommitdiff
path: root/src/lj_tab.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_tab.h')
-rw-r--r--src/lj_tab.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lj_tab.h b/src/lj_tab.h
new file mode 100644
index 00000000..e9e8bcd1
--- /dev/null
+++ b/src/lj_tab.h
@@ -0,0 +1,41 @@
1/*
2** Table handling.
3** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h
4*/
5
6#ifndef _LJ_TAB_H
7#define _LJ_TAB_H
8
9#include "lj_obj.h"
10
11#define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)
12
13LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);
14LJ_FUNCA GCtab *lj_tab_dup(lua_State *L, const GCtab *kt);
15LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);
16LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);
17
18/* Caveat: all getters except lj_tab_get() can return NULL! */
19
20LJ_FUNCA cTValue *lj_tab_getinth(GCtab *t, int32_t key);
21LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key);
22LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);
23
24/* Caveat: all setters require a write barrier for the stored value. */
25
26LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);
27LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);
28LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key);
29LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);
30
31#define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize)
32#define arrayslot(t, i) (&tvref((t)->array)[(i)])
33#define lj_tab_getint(t, key) \
34 (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))
35#define lj_tab_setint(L, t, key) \
36 (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))
37
38LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key);
39LJ_FUNCA MSize lj_tab_len(GCtab *t);
40
41#endif