diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-24 13:45:33 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-24 13:45:33 -0200 |
commit | 71ae4801d66d9592b0fb08e4e78138b7a6e993d5 (patch) | |
tree | a683b5b3757efb979329bf513f1bd9fde3fb9d1f /lapi.c | |
parent | 6fda6a530265268c01a83c31f8fc30e34753bbf1 (diff) | |
download | lua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.tar.gz lua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.tar.bz2 lua-71ae4801d66d9592b0fb08e4e78138b7a6e993d5.zip |
macros LUA_ENTRY/LUA_EXIT to control exclusive access to Lua core
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 321 |
1 files changed, 249 insertions, 72 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.117 2001/01/18 15:59:09 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.118 2001/01/19 13:20:30 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -54,7 +54,11 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
54 | } | 54 | } |
55 | 55 | ||
56 | LUA_API int lua_stackspace (lua_State *L) { | 56 | LUA_API int lua_stackspace (lua_State *L) { |
57 | return (L->stack_last - L->top); | 57 | int i; |
58 | LUA_ENTRY; | ||
59 | i = (L->stack_last - L->top); | ||
60 | LUA_EXIT; | ||
61 | return i; | ||
58 | } | 62 | } |
59 | 63 | ||
60 | 64 | ||
@@ -65,36 +69,50 @@ LUA_API int lua_stackspace (lua_State *L) { | |||
65 | 69 | ||
66 | 70 | ||
67 | LUA_API int lua_gettop (lua_State *L) { | 71 | LUA_API int lua_gettop (lua_State *L) { |
68 | return (L->top - L->Cbase); | 72 | int i; |
73 | LUA_ENTRY; | ||
74 | i = (L->top - L->Cbase); | ||
75 | LUA_EXIT; | ||
76 | return i; | ||
69 | } | 77 | } |
70 | 78 | ||
71 | 79 | ||
72 | LUA_API void lua_settop (lua_State *L, int index) { | 80 | LUA_API void lua_settop (lua_State *L, int index) { |
81 | LUA_ENTRY; | ||
73 | if (index >= 0) | 82 | if (index >= 0) |
74 | luaD_adjusttop(L, L->Cbase, index); | 83 | luaD_adjusttop(L, L->Cbase, index); |
75 | else | 84 | else |
76 | L->top = L->top+index+1; /* index is negative */ | 85 | L->top = L->top+index+1; /* index is negative */ |
86 | LUA_EXIT; | ||
77 | } | 87 | } |
78 | 88 | ||
79 | 89 | ||
80 | LUA_API void lua_remove (lua_State *L, int index) { | 90 | LUA_API void lua_remove (lua_State *L, int index) { |
81 | StkId p = luaA_index(L, index); | 91 | StkId p; |
92 | LUA_ENTRY; | ||
93 | p = luaA_index(L, index); | ||
82 | while (++p < L->top) setobj(p-1, p); | 94 | while (++p < L->top) setobj(p-1, p); |
83 | L->top--; | 95 | L->top--; |
96 | LUA_EXIT; | ||
84 | } | 97 | } |
85 | 98 | ||
86 | 99 | ||
87 | LUA_API void lua_insert (lua_State *L, int index) { | 100 | LUA_API void lua_insert (lua_State *L, int index) { |
88 | StkId p = luaA_index(L, index); | 101 | StkId p; |
89 | StkId q; | 102 | StkId q; |
103 | LUA_ENTRY; | ||
104 | p = luaA_index(L, index); | ||
90 | for (q = L->top; q>p; q--) setobj(q, q-1); | 105 | for (q = L->top; q>p; q--) setobj(q, q-1); |
91 | setobj(p, L->top); | 106 | setobj(p, L->top); |
107 | LUA_EXIT; | ||
92 | } | 108 | } |
93 | 109 | ||
94 | 110 | ||
95 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 111 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
112 | LUA_ENTRY; | ||
96 | setobj(L->top, luaA_index(L, index)); | 113 | setobj(L->top, luaA_index(L, index)); |
97 | api_incr_top(L); | 114 | api_incr_top(L); |
115 | LUA_EXIT; | ||
98 | } | 116 | } |
99 | 117 | ||
100 | 118 | ||
@@ -105,24 +123,43 @@ LUA_API void lua_pushvalue (lua_State *L, int index) { | |||
105 | 123 | ||
106 | 124 | ||
107 | LUA_API int lua_type (lua_State *L, int index) { | 125 | LUA_API int lua_type (lua_State *L, int index) { |
108 | StkId o = luaA_indexAcceptable(L, index); | 126 | StkId o; |
109 | return (o == NULL) ? LUA_TNONE : ttype(o); | 127 | int i; |
128 | LUA_ENTRY; | ||
129 | o = luaA_indexAcceptable(L, index); | ||
130 | i = (o == NULL) ? LUA_TNONE : ttype(o); | ||
131 | LUA_EXIT; | ||
132 | return i; | ||
110 | } | 133 | } |
111 | 134 | ||
112 | LUA_API const char *lua_typename (lua_State *L, int t) { | 135 | LUA_API const char *lua_typename (lua_State *L, int t) { |
136 | const char *s; | ||
137 | LUA_ENTRY; | ||
113 | UNUSED(L); | 138 | UNUSED(L); |
114 | return (t == LUA_TNONE) ? "no value" : luaO_typenames[t]; | 139 | s = (t == LUA_TNONE) ? "no value" : luaO_typenames[t]; |
140 | LUA_EXIT; | ||
141 | return s; | ||
115 | } | 142 | } |
116 | 143 | ||
117 | 144 | ||
118 | LUA_API int lua_iscfunction (lua_State *L, int index) { | 145 | LUA_API int lua_iscfunction (lua_State *L, int index) { |
119 | StkId o = luaA_indexAcceptable(L, index); | 146 | StkId o; |
120 | return (o == NULL) ? 0 : iscfunction(o); | 147 | int i; |
148 | LUA_ENTRY; | ||
149 | o = luaA_indexAcceptable(L, index); | ||
150 | i = (o == NULL) ? 0 : iscfunction(o); | ||
151 | LUA_EXIT; | ||
152 | return i; | ||
121 | } | 153 | } |
122 | 154 | ||
123 | LUA_API int lua_isnumber (lua_State *L, int index) { | 155 | LUA_API int lua_isnumber (lua_State *L, int index) { |
124 | TObject *o = luaA_indexAcceptable(L, index); | 156 | TObject *o; |
125 | return (o == NULL) ? 0 : (tonumber(o) == 0); | 157 | int i; |
158 | LUA_ENTRY; | ||
159 | o = luaA_indexAcceptable(L, index); | ||
160 | i = (o == NULL) ? 0 : (tonumber(o) == 0); | ||
161 | LUA_EXIT; | ||
162 | return i; | ||
126 | } | 163 | } |
127 | 164 | ||
128 | LUA_API int lua_isstring (lua_State *L, int index) { | 165 | LUA_API int lua_isstring (lua_State *L, int index) { |
@@ -132,62 +169,113 @@ LUA_API int lua_isstring (lua_State *L, int index) { | |||
132 | 169 | ||
133 | 170 | ||
134 | LUA_API int lua_tag (lua_State *L, int index) { | 171 | LUA_API int lua_tag (lua_State *L, int index) { |
135 | StkId o = luaA_indexAcceptable(L, index); | 172 | StkId o; |
136 | return (o == NULL) ? LUA_NOTAG : luaT_tag(o); | 173 | int i; |
174 | LUA_ENTRY; | ||
175 | o = luaA_indexAcceptable(L, index); | ||
176 | i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); | ||
177 | LUA_EXIT; | ||
178 | return i; | ||
137 | } | 179 | } |
138 | 180 | ||
139 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 181 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { |
140 | StkId o1 = luaA_indexAcceptable(L, index1); | 182 | StkId o1, o2; |
141 | StkId o2 = luaA_indexAcceptable(L, index2); | 183 | int i; |
142 | if (o1 == NULL || o2 == NULL) return 0; /* index out-of-range */ | 184 | LUA_ENTRY; |
143 | else return luaO_equalObj(o1, o2); | 185 | o1 = luaA_indexAcceptable(L, index1); |
186 | o2 = luaA_indexAcceptable(L, index2); | ||
187 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | ||
188 | : luaO_equalObj(o1, o2); | ||
189 | LUA_EXIT; | ||
190 | return i; | ||
144 | } | 191 | } |
145 | 192 | ||
146 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | 193 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { |
147 | StkId o1 = luaA_indexAcceptable(L, index1); | 194 | StkId o1, o2; |
148 | StkId o2 = luaA_indexAcceptable(L, index2); | 195 | int i; |
149 | if (o1 == NULL || o2 == NULL) return 0; /* index out-of-range */ | 196 | LUA_ENTRY; |
150 | else return luaV_lessthan(L, o1, o2, L->top); | 197 | o1 = luaA_indexAcceptable(L, index1); |
198 | o2 = luaA_indexAcceptable(L, index2); | ||
199 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | ||
200 | : luaV_lessthan(L, o1, o2, L->top); | ||
201 | LUA_EXIT; | ||
202 | return i; | ||
151 | } | 203 | } |
152 | 204 | ||
153 | 205 | ||
154 | 206 | ||
155 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | 207 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { |
156 | StkId o = luaA_indexAcceptable(L, index); | 208 | StkId o; |
157 | return (o == NULL || tonumber(o)) ? 0 : nvalue(o); | 209 | lua_Number n; |
210 | LUA_ENTRY; | ||
211 | o = luaA_indexAcceptable(L, index); | ||
212 | n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); | ||
213 | LUA_EXIT; | ||
214 | return n; | ||
158 | } | 215 | } |
159 | 216 | ||
160 | LUA_API const char *lua_tostring (lua_State *L, int index) { | 217 | LUA_API const char *lua_tostring (lua_State *L, int index) { |
161 | StkId o = luaA_indexAcceptable(L, index); | 218 | StkId o; |
162 | return (o == NULL || tostring(L, o)) ? NULL : svalue(o); | 219 | const char *s; |
220 | LUA_ENTRY; | ||
221 | o = luaA_indexAcceptable(L, index); | ||
222 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); | ||
223 | LUA_EXIT; | ||
224 | return s; | ||
163 | } | 225 | } |
164 | 226 | ||
165 | LUA_API size_t lua_strlen (lua_State *L, int index) { | 227 | LUA_API size_t lua_strlen (lua_State *L, int index) { |
166 | StkId o = luaA_indexAcceptable(L, index); | 228 | StkId o; |
167 | return (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; | 229 | size_t l; |
230 | LUA_ENTRY; | ||
231 | o = luaA_indexAcceptable(L, index); | ||
232 | l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; | ||
233 | LUA_EXIT; | ||
234 | return l; | ||
168 | } | 235 | } |
169 | 236 | ||
170 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | 237 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { |
171 | StkId o = luaA_indexAcceptable(L, index); | 238 | StkId o; |
172 | return (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; | 239 | lua_CFunction f; |
240 | LUA_ENTRY; | ||
241 | o = luaA_indexAcceptable(L, index); | ||
242 | f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; | ||
243 | LUA_EXIT; | ||
244 | return f; | ||
173 | } | 245 | } |
174 | 246 | ||
175 | LUA_API void *lua_touserdata (lua_State *L, int index) { | 247 | LUA_API void *lua_touserdata (lua_State *L, int index) { |
176 | StkId o = luaA_indexAcceptable(L, index); | 248 | StkId o; |
177 | return (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : | 249 | void *p; |
250 | LUA_ENTRY; | ||
251 | o = luaA_indexAcceptable(L, index); | ||
252 | p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : | ||
178 | tsvalue(o)->u.d.value; | 253 | tsvalue(o)->u.d.value; |
254 | LUA_EXIT; | ||
255 | return p; | ||
179 | } | 256 | } |
180 | 257 | ||
181 | LUA_API const void *lua_topointer (lua_State *L, int index) { | 258 | LUA_API const void *lua_topointer (lua_State *L, int index) { |
182 | StkId o = luaA_indexAcceptable(L, index); | 259 | StkId o; |
183 | if (o == NULL) return NULL; | 260 | const void *p; |
184 | switch (ttype(o)) { | 261 | LUA_ENTRY; |
185 | case LUA_TTABLE: | 262 | o = luaA_indexAcceptable(L, index); |
186 | return hvalue(o); | 263 | if (o == NULL) p = NULL; |
187 | case LUA_TFUNCTION: | 264 | else { |
188 | return clvalue(o); | 265 | switch (ttype(o)) { |
189 | default: return NULL; | 266 | case LUA_TTABLE: |
267 | p = hvalue(o); | ||
268 | break; | ||
269 | case LUA_TFUNCTION: | ||
270 | p = clvalue(o); | ||
271 | break; | ||
272 | default: | ||
273 | p = NULL; | ||
274 | break; | ||
275 | } | ||
190 | } | 276 | } |
277 | LUA_EXIT; | ||
278 | return p; | ||
191 | } | 279 | } |
192 | 280 | ||
193 | 281 | ||
@@ -198,20 +286,26 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
198 | 286 | ||
199 | 287 | ||
200 | LUA_API void lua_pushnil (lua_State *L) { | 288 | LUA_API void lua_pushnil (lua_State *L) { |
289 | LUA_ENTRY; | ||
201 | setnilvalue(L->top); | 290 | setnilvalue(L->top); |
202 | api_incr_top(L); | 291 | api_incr_top(L); |
292 | LUA_EXIT; | ||
203 | } | 293 | } |
204 | 294 | ||
205 | 295 | ||
206 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 296 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
297 | LUA_ENTRY; | ||
207 | setnvalue(L->top, n); | 298 | setnvalue(L->top, n); |
208 | api_incr_top(L); | 299 | api_incr_top(L); |
300 | LUA_EXIT; | ||
209 | } | 301 | } |
210 | 302 | ||
211 | 303 | ||
212 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 304 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
305 | LUA_ENTRY; | ||
213 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 306 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
214 | api_incr_top(L); | 307 | api_incr_top(L); |
308 | LUA_EXIT; | ||
215 | } | 309 | } |
216 | 310 | ||
217 | 311 | ||
@@ -224,16 +318,20 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) { | |||
224 | 318 | ||
225 | 319 | ||
226 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 320 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
321 | LUA_ENTRY; | ||
227 | luaV_Cclosure(L, fn, n); | 322 | luaV_Cclosure(L, fn, n); |
323 | LUA_EXIT; | ||
228 | } | 324 | } |
229 | 325 | ||
230 | 326 | ||
231 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | 327 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { |
328 | LUA_ENTRY; | ||
232 | /* ORDER LUA_T */ | 329 | /* ORDER LUA_T */ |
233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) | 330 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) |
234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 331 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
235 | setuvalue(L->top, luaS_createudata(L, u, tag)); | 332 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
236 | api_incr_top(L); | 333 | api_incr_top(L); |
334 | LUA_EXIT; | ||
237 | } | 335 | } |
238 | 336 | ||
239 | 337 | ||
@@ -244,60 +342,80 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
244 | 342 | ||
245 | 343 | ||
246 | LUA_API void lua_getglobal (lua_State *L, const char *name) { | 344 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
247 | StkId top = L->top; | 345 | StkId top; |
346 | LUA_ENTRY; | ||
347 | top = L->top; | ||
248 | setobj(top, luaV_getglobal(L, luaS_new(L, name))); | 348 | setobj(top, luaV_getglobal(L, luaS_new(L, name))); |
249 | L->top = top; | 349 | L->top = top; |
250 | api_incr_top(L); | 350 | api_incr_top(L); |
351 | LUA_EXIT; | ||
251 | } | 352 | } |
252 | 353 | ||
253 | 354 | ||
254 | LUA_API void lua_gettable (lua_State *L, int index) { | 355 | LUA_API void lua_gettable (lua_State *L, int index) { |
255 | StkId t = Index(L, index); | 356 | StkId t, top; |
256 | StkId top = L->top; | 357 | LUA_ENTRY; |
358 | t = Index(L, index); | ||
359 | top = L->top; | ||
257 | setobj(top-1, luaV_gettable(L, t)); | 360 | setobj(top-1, luaV_gettable(L, t)); |
258 | L->top = top; /* tag method may change top */ | 361 | L->top = top; /* tag method may change top */ |
362 | LUA_EXIT; | ||
259 | } | 363 | } |
260 | 364 | ||
261 | 365 | ||
262 | LUA_API void lua_rawget (lua_State *L, int index) { | 366 | LUA_API void lua_rawget (lua_State *L, int index) { |
263 | StkId t = Index(L, index); | 367 | StkId t; |
368 | LUA_ENTRY; | ||
369 | t = Index(L, index); | ||
264 | lua_assert(ttype(t) == LUA_TTABLE); | 370 | lua_assert(ttype(t) == LUA_TTABLE); |
265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 371 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
372 | LUA_EXIT; | ||
266 | } | 373 | } |
267 | 374 | ||
268 | 375 | ||
269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 376 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
270 | StkId o = Index(L, index); | 377 | StkId o; |
378 | LUA_ENTRY; | ||
379 | o = Index(L, index); | ||
271 | lua_assert(ttype(o) == LUA_TTABLE); | 380 | lua_assert(ttype(o) == LUA_TTABLE); |
272 | setobj(L->top, luaH_getnum(hvalue(o), n)); | 381 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
273 | api_incr_top(L); | 382 | api_incr_top(L); |
383 | LUA_EXIT; | ||
274 | } | 384 | } |
275 | 385 | ||
276 | 386 | ||
277 | LUA_API void lua_getglobals (lua_State *L) { | 387 | LUA_API void lua_getglobals (lua_State *L) { |
388 | LUA_ENTRY; | ||
278 | sethvalue(L->top, L->gt); | 389 | sethvalue(L->top, L->gt); |
279 | api_incr_top(L); | 390 | api_incr_top(L); |
391 | LUA_EXIT; | ||
280 | } | 392 | } |
281 | 393 | ||
282 | 394 | ||
283 | LUA_API int lua_getref (lua_State *L, int ref) { | 395 | LUA_API int lua_getref (lua_State *L, int ref) { |
396 | int status = 1; | ||
397 | LUA_ENTRY; | ||
284 | if (ref == LUA_REFNIL) { | 398 | if (ref == LUA_REFNIL) { |
285 | setnilvalue(L->top); | 399 | setnilvalue(L->top); |
400 | api_incr_top(L); | ||
286 | } | 401 | } |
287 | else if (0 <= ref && ref < G(L)->nref && | 402 | else if (0 <= ref && ref < G(L)->nref && |
288 | (G(L)->refArray[ref].st == LOCK || G(L)->refArray[ref].st == HOLD)) { | 403 | (G(L)->refArray[ref].st == LOCK || G(L)->refArray[ref].st == HOLD)) { |
289 | setobj(L->top, &G(L)->refArray[ref].o); | 404 | setobj(L->top, &G(L)->refArray[ref].o); |
405 | api_incr_top(L); | ||
290 | } | 406 | } |
291 | else | 407 | else |
292 | return 0; | 408 | status = 0; |
293 | api_incr_top(L); | 409 | LUA_EXIT; |
294 | return 1; | 410 | return status; |
295 | } | 411 | } |
296 | 412 | ||
297 | 413 | ||
298 | LUA_API void lua_newtable (lua_State *L) { | 414 | LUA_API void lua_newtable (lua_State *L) { |
415 | LUA_ENTRY; | ||
299 | sethvalue(L->top, luaH_new(L, 0)); | 416 | sethvalue(L->top, luaH_new(L, 0)); |
300 | api_incr_top(L); | 417 | api_incr_top(L); |
418 | LUA_EXIT; | ||
301 | } | 419 | } |
302 | 420 | ||
303 | 421 | ||
@@ -308,45 +426,61 @@ LUA_API void lua_newtable (lua_State *L) { | |||
308 | 426 | ||
309 | 427 | ||
310 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 428 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
311 | StkId top = L->top; | 429 | StkId top; |
430 | LUA_ENTRY; | ||
431 | top = L->top; | ||
312 | luaV_setglobal(L, luaS_new(L, name)); | 432 | luaV_setglobal(L, luaS_new(L, name)); |
313 | L->top = top-1; /* remove element from the top */ | 433 | L->top = top-1; /* remove element from the top */ |
434 | LUA_EXIT; | ||
314 | } | 435 | } |
315 | 436 | ||
316 | 437 | ||
317 | LUA_API void lua_settable (lua_State *L, int index) { | 438 | LUA_API void lua_settable (lua_State *L, int index) { |
318 | StkId t = Index(L, index); | 439 | StkId t, top; |
319 | StkId top = L->top; | 440 | LUA_ENTRY; |
441 | t = Index(L, index); | ||
442 | top = L->top; | ||
320 | luaV_settable(L, t, top-2); | 443 | luaV_settable(L, t, top-2); |
321 | L->top = top-2; /* pop index and value */ | 444 | L->top = top-2; /* pop index and value */ |
445 | LUA_EXIT; | ||
322 | } | 446 | } |
323 | 447 | ||
324 | 448 | ||
325 | LUA_API void lua_rawset (lua_State *L, int index) { | 449 | LUA_API void lua_rawset (lua_State *L, int index) { |
326 | StkId t = Index(L, index); | 450 | StkId t; |
451 | LUA_ENTRY; | ||
452 | t = Index(L, index); | ||
327 | lua_assert(ttype(t) == LUA_TTABLE); | 453 | lua_assert(ttype(t) == LUA_TTABLE); |
328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); | 454 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
329 | L->top -= 2; | 455 | L->top -= 2; |
456 | LUA_EXIT; | ||
330 | } | 457 | } |
331 | 458 | ||
332 | 459 | ||
333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 460 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
334 | StkId o = Index(L, index); | 461 | StkId o; |
462 | LUA_ENTRY; | ||
463 | o = Index(L, index); | ||
335 | lua_assert(ttype(o) == LUA_TTABLE); | 464 | lua_assert(ttype(o) == LUA_TTABLE); |
336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); | 465 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
337 | L->top--; | 466 | L->top--; |
467 | LUA_EXIT; | ||
338 | } | 468 | } |
339 | 469 | ||
340 | 470 | ||
341 | LUA_API void lua_setglobals (lua_State *L) { | 471 | LUA_API void lua_setglobals (lua_State *L) { |
342 | StkId newtable = --L->top; | 472 | StkId newtable; |
473 | LUA_ENTRY; | ||
474 | newtable = --L->top; | ||
343 | lua_assert(ttype(newtable) == LUA_TTABLE); | 475 | lua_assert(ttype(newtable) == LUA_TTABLE); |
344 | L->gt = hvalue(newtable); | 476 | L->gt = hvalue(newtable); |
477 | LUA_EXIT; | ||
345 | } | 478 | } |
346 | 479 | ||
347 | 480 | ||
348 | LUA_API int lua_ref (lua_State *L, int lock) { | 481 | LUA_API int lua_ref (lua_State *L, int lock) { |
349 | int ref; | 482 | int ref; |
483 | LUA_ENTRY; | ||
350 | if (ttype(L->top-1) == LUA_TNIL) | 484 | if (ttype(L->top-1) == LUA_TNIL) |
351 | ref = LUA_REFNIL; | 485 | ref = LUA_REFNIL; |
352 | else { | 486 | else { |
@@ -363,6 +497,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
363 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; | 497 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; |
364 | } | 498 | } |
365 | L->top--; | 499 | L->top--; |
500 | LUA_EXIT; | ||
366 | return ref; | 501 | return ref; |
367 | } | 502 | } |
368 | 503 | ||
@@ -373,7 +508,9 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
373 | */ | 508 | */ |
374 | 509 | ||
375 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | 510 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { |
511 | LUA_ENTRY; | ||
376 | luaD_call(L, L->top-(nargs+1), nresults); | 512 | luaD_call(L, L->top-(nargs+1), nresults); |
513 | LUA_EXIT; | ||
377 | } | 514 | } |
378 | 515 | ||
379 | 516 | ||
@@ -386,19 +523,29 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
386 | #define GCunscale(x) ((mem_int)(x)<<10) | 523 | #define GCunscale(x) ((mem_int)(x)<<10) |
387 | 524 | ||
388 | LUA_API int lua_getgcthreshold (lua_State *L) { | 525 | LUA_API int lua_getgcthreshold (lua_State *L) { |
389 | return GCscale(G(L)->GCthreshold); | 526 | int threshold; |
527 | LUA_ENTRY; | ||
528 | threshold = GCscale(G(L)->GCthreshold); | ||
529 | LUA_EXIT; | ||
530 | return threshold; | ||
390 | } | 531 | } |
391 | 532 | ||
392 | LUA_API int lua_getgccount (lua_State *L) { | 533 | LUA_API int lua_getgccount (lua_State *L) { |
393 | return GCscale(G(L)->nblocks); | 534 | int count; |
535 | LUA_ENTRY; | ||
536 | count = GCscale(G(L)->nblocks); | ||
537 | LUA_EXIT; | ||
538 | return count; | ||
394 | } | 539 | } |
395 | 540 | ||
396 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | 541 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { |
542 | LUA_ENTRY; | ||
397 | if (newthreshold > GCscale(ULONG_MAX)) | 543 | if (newthreshold > GCscale(ULONG_MAX)) |
398 | G(L)->GCthreshold = ULONG_MAX; | 544 | G(L)->GCthreshold = ULONG_MAX; |
399 | else | 545 | else |
400 | G(L)->GCthreshold = GCunscale(newthreshold); | 546 | G(L)->GCthreshold = GCunscale(newthreshold); |
401 | luaC_checkGC(L); | 547 | luaC_checkGC(L); |
548 | LUA_EXIT; | ||
402 | } | 549 | } |
403 | 550 | ||
404 | 551 | ||
@@ -407,6 +554,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
407 | */ | 554 | */ |
408 | 555 | ||
409 | LUA_API void lua_settag (lua_State *L, int tag) { | 556 | LUA_API void lua_settag (lua_State *L, int tag) { |
557 | LUA_ENTRY; | ||
410 | luaT_realtag(L, tag); | 558 | luaT_realtag(L, tag); |
411 | switch (ttype(L->top-1)) { | 559 | switch (ttype(L->top-1)) { |
412 | case LUA_TTABLE: | 560 | case LUA_TTABLE: |
@@ -419,69 +567,98 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
419 | luaO_verror(L, "cannot change the tag of a %.20s", | 567 | luaO_verror(L, "cannot change the tag of a %.20s", |
420 | luaO_typename(L->top-1)); | 568 | luaO_typename(L->top-1)); |
421 | } | 569 | } |
570 | LUA_EXIT; | ||
571 | } | ||
572 | |||
573 | |||
574 | LUA_API void lua_error (lua_State *L, const char *s) { | ||
575 | LUA_ENTRY; | ||
576 | luaD_error(L, s); | ||
577 | LUA_EXIT; | ||
422 | } | 578 | } |
423 | 579 | ||
424 | 580 | ||
425 | LUA_API void lua_unref (lua_State *L, int ref) { | 581 | LUA_API void lua_unref (lua_State *L, int ref) { |
582 | LUA_ENTRY; | ||
426 | if (ref >= 0) { | 583 | if (ref >= 0) { |
427 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); | 584 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); |
428 | G(L)->refArray[ref].st = G(L)->refFree; | 585 | G(L)->refArray[ref].st = G(L)->refFree; |
429 | G(L)->refFree = ref; | 586 | G(L)->refFree = ref; |
430 | } | 587 | } |
588 | LUA_EXIT; | ||
431 | } | 589 | } |
432 | 590 | ||
433 | 591 | ||
434 | LUA_API int lua_next (lua_State *L, int index) { | 592 | LUA_API int lua_next (lua_State *L, int index) { |
435 | StkId t = luaA_index(L, index); | 593 | StkId t; |
436 | Node *n; | 594 | Node *n; |
595 | int more; | ||
596 | LUA_ENTRY; | ||
597 | t = luaA_index(L, index); | ||
437 | lua_assert(ttype(t) == LUA_TTABLE); | 598 | lua_assert(ttype(t) == LUA_TTABLE); |
438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 599 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
439 | if (n) { | 600 | if (n) { |
440 | setobj(L->top-1, key(n)); | 601 | setobj(L->top-1, key(n)); |
441 | setobj(L->top, val(n)); | 602 | setobj(L->top, val(n)); |
442 | api_incr_top(L); | 603 | api_incr_top(L); |
443 | return 1; | 604 | more = 1; |
444 | } | 605 | } |
445 | else { /* no more elements */ | 606 | else { /* no more elements */ |
446 | L->top -= 1; /* remove key */ | 607 | L->top -= 1; /* remove key */ |
447 | return 0; | 608 | more = 0; |
448 | } | 609 | } |
610 | LUA_EXIT; | ||
611 | return more; | ||
449 | } | 612 | } |
450 | 613 | ||
451 | 614 | ||
452 | LUA_API int lua_getn (lua_State *L, int index) { | 615 | LUA_API int lua_getn (lua_State *L, int index) { |
453 | Hash *h = hvalue(luaA_index(L, index)); | 616 | Hash *h; |
454 | const TObject *value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ | 617 | const TObject *value; |
618 | int n; | ||
619 | LUA_ENTRY; | ||
620 | h = hvalue(luaA_index(L, index)); | ||
621 | value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ | ||
455 | if (ttype(value) == LUA_TNUMBER) | 622 | if (ttype(value) == LUA_TNUMBER) |
456 | return (int)nvalue(value); | 623 | n = (int)nvalue(value); |
457 | else { | 624 | else { |
458 | lua_Number max = 0; | 625 | lua_Number max = 0; |
459 | int i = h->size; | 626 | int i = h->size; |
460 | Node *n = h->node; | 627 | Node *nd = h->node; |
461 | while (i--) { | 628 | while (i--) { |
462 | if (ttype(key(n)) == LUA_TNUMBER && | 629 | if (ttype(key(nd)) == LUA_TNUMBER && |
463 | ttype(val(n)) != LUA_TNIL && | 630 | ttype(val(nd)) != LUA_TNIL && |
464 | nvalue(key(n)) > max) | 631 | nvalue(key(nd)) > max) |
465 | max = nvalue(key(n)); | 632 | max = nvalue(key(nd)); |
466 | n++; | 633 | nd++; |
467 | } | 634 | } |
468 | return (int)max; | 635 | n = (int)max; |
469 | } | 636 | } |
637 | LUA_EXIT; | ||
638 | return n; | ||
470 | } | 639 | } |
471 | 640 | ||
472 | 641 | ||
473 | LUA_API void lua_concat (lua_State *L, int n) { | 642 | LUA_API void lua_concat (lua_State *L, int n) { |
474 | StkId top = L->top; | 643 | StkId top; |
644 | LUA_ENTRY; | ||
645 | top = L->top; | ||
475 | luaV_strconc(L, n, top); | 646 | luaV_strconc(L, n, top); |
476 | L->top = top-(n-1); | 647 | L->top = top-(n-1); |
477 | luaC_checkGC(L); | 648 | luaC_checkGC(L); |
649 | LUA_EXIT; | ||
478 | } | 650 | } |
479 | 651 | ||
480 | 652 | ||
481 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 653 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
482 | TString *ts = luaS_newudata(L, size, NULL); | 654 | TString *ts; |
655 | void *p; | ||
656 | LUA_ENTRY; | ||
657 | ts = luaS_newudata(L, size, NULL); | ||
483 | setuvalue(L->top, ts); | 658 | setuvalue(L->top, ts); |
484 | api_incr_top(L); | 659 | api_incr_top(L); |
485 | return ts->u.d.value; | 660 | p = ts->u.d.value; |
661 | LUA_EXIT; | ||
662 | return p; | ||
486 | } | 663 | } |
487 | 664 | ||