aboutsummaryrefslogtreecommitdiff
path: root/ltable.h
diff options
context:
space:
mode:
Diffstat (limited to 'ltable.h')
-rw-r--r--ltable.h99
1 files changed, 94 insertions, 5 deletions
diff --git a/ltable.h b/ltable.h
index 30cfc8be..210ae7ac 100644
--- a/ltable.h
+++ b/ltable.h
@@ -45,16 +45,105 @@
45#define nodefromval(v) cast(Node *, (v)) 45#define nodefromval(v) cast(Node *, (v))
46 46
47 47
48LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 48/* results from get/pset */
49#define HOK 0
50#define HNOTFOUND 1
51#define HNOTATABLE 2
52#define HFIRSTNODE 3
53
54/*
55** Besides these values, pset (pre-set) operations may also return an
56** encoding of where the value should go (usually called 'hres'). That
57** means that there is a slot with that key but with no value. (pset
58** cannot set that value because there might be a metamethod.) If the
59** slot is in the hash part, the encoding is (HFIRSTNODE + hash index);
60** if the slot is in the array part, the encoding is (~array index).
61*/
62
63
64/*
65** The array part of a table is represented by an array of cells.
66** Each cell is composed of (NM + 1) elements, and each element has the
67** type 'ArrayCell'. In each cell, only one element has the variant
68** 'tag', while the other NM elements have the variant 'value'. The
69** array in the 'tag' element holds the tags of the other elements in
70** that cell.
71*/
72#define NM ((unsigned int)sizeof(Value))
73
74union ArrayCell {
75 unsigned char tag[NM];
76 Value value;
77};
78
79
80/*
81** 'NMTag' defines which cell element has the tags; that could be any
82** value between 0 (tags come before all values) and NM (tags come after
83** all values).
84*/
85#define NMTag 0
86
87
88/*
89** Computes the concrete index that holds the tag of abstract index 'i'
90*/
91#define TagIndex(i) (((i)/NM * (NM + 1u)) + NMTag)
92
93/*
94** Computes the concrete index that holds the value of abstract index 'i'
95*/
96#define ValueIndex(i) ((i) + (((i) + (NM - NMTag))/NM))
97
98
99/* Computes the address of the tag for the abstract index 'k' */
100#define getArrTag(t,k) (&(t)->array[TagIndex(k)].tag[(k)%NM])
101
102/* Computes the address of the value for the abstract index 'k' */
103#define getArrVal(t,k) (&(t)->array[ValueIndex(k)].value)
104
105
106/*
107** Move TValues to/from arrays, using Lua indices
108*/
109#define arr2obj(h,k,val) \
110 ((val)->tt_ = *getArrTag(h,(k)-1u), (val)->value_ = *getArrVal(h,(k)-1u))
111
112#define obj2arr(h,k,val) \
113 (*getArrTag(h,(k)-1u) = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_)
114
115
116/*
117** Often, we need to check the tag of a value before moving it. These
118** macros also move TValues to/from arrays, but receive the precomputed
119** tag value or address as an extra argument.
120*/
121#define farr2val(h,k,tag,res) \
122 ((res)->tt_ = tag, (res)->value_ = *getArrVal(h,(k)-1u))
123
124#define fval2arr(h,k,tag,val) \
125 (*tag = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_)
126
127
128LUAI_FUNC int luaH_getshortstr (Table *t, TString *key, TValue *res);
129LUAI_FUNC int luaH_getstr (Table *t, TString *key, TValue *res);
130LUAI_FUNC int luaH_get (Table *t, const TValue *key, TValue *res);
131LUAI_FUNC int luaH_getint (Table *t, lua_Integer key, TValue *res);
132
133LUAI_FUNC TString *luaH_getstrkey (Table *t, TString *key);
134
135LUAI_FUNC int luaH_psetint (Table *t, lua_Integer key, TValue *val);
136LUAI_FUNC int luaH_psetshortstr (Table *t, TString *key, TValue *val);
137LUAI_FUNC int luaH_psetstr (Table *t, TString *key, TValue *val);
138LUAI_FUNC int luaH_pset (Table *t, const TValue *key, TValue *val);
139
49LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 140LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
50 TValue *value); 141 TValue *value);
51LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 142LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key);
52LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
53LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
54LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 143LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key,
55 TValue *value); 144 TValue *value);
56LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 145LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key,
57 const TValue *slot, TValue *value); 146 TValue *value, int aux);
58LUAI_FUNC Table *luaH_new (lua_State *L); 147LUAI_FUNC Table *luaH_new (lua_State *L);
59LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 148LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
60 unsigned int nhsize); 149 unsigned int nhsize);