aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-26 09:45:51 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-26 09:45:51 -0200
commitbce6572579a7e6c7a96895d9280396b3b33b8f3f (patch)
treea937d0366ae9d9e37e6320b347ec463f337ceb1b /lapi.c
parenta53d9b66ca6247818acaf41e28cdf123082a272b (diff)
downloadlua-bce6572579a7e6c7a96895d9280396b3b33b8f3f.tar.gz
lua-bce6572579a7e6c7a96895d9280396b3b33b8f3f.tar.bz2
lua-bce6572579a7e6c7a96895d9280396b3b33b8f3f.zip
new macros + new names to facilitate compilation of threaded version
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c208
1 files changed, 104 insertions, 104 deletions
diff --git a/lapi.c b/lapi.c
index d9229444..26563daf 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.119 2001/01/24 15:45:33 roberto Exp roberto $ 2** $Id: lapi.c,v 1.120 2001/01/25 16:45:36 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*/
@@ -55,9 +55,9 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
55 55
56LUA_API int lua_stackspace (lua_State *L) { 56LUA_API int lua_stackspace (lua_State *L) {
57 int i; 57 int i;
58 LUA_ENTRY; 58 LUA_LOCK;
59 i = (L->stack_last - L->top); 59 i = (L->stack_last - L->top);
60 LUA_EXIT; 60 LUA_UNLOCK;
61 return i; 61 return i;
62} 62}
63 63
@@ -70,49 +70,49 @@ LUA_API int lua_stackspace (lua_State *L) {
70 70
71LUA_API int lua_gettop (lua_State *L) { 71LUA_API int lua_gettop (lua_State *L) {
72 int i; 72 int i;
73 LUA_ENTRY; 73 LUA_LOCK;
74 i = (L->top - L->Cbase); 74 i = (L->top - L->Cbase);
75 LUA_EXIT; 75 LUA_UNLOCK;
76 return i; 76 return i;
77} 77}
78 78
79 79
80LUA_API void lua_settop (lua_State *L, int index) { 80LUA_API void lua_settop (lua_State *L, int index) {
81 LUA_ENTRY; 81 LUA_LOCK;
82 if (index >= 0) 82 if (index >= 0)
83 luaD_adjusttop(L, L->Cbase, index); 83 luaD_adjusttop(L, L->Cbase, index);
84 else 84 else
85 L->top = L->top+index+1; /* index is negative */ 85 L->top = L->top+index+1; /* index is negative */
86 LUA_EXIT; 86 LUA_UNLOCK;
87} 87}
88 88
89 89
90LUA_API void lua_remove (lua_State *L, int index) { 90LUA_API void lua_remove (lua_State *L, int index) {
91 StkId p; 91 StkId p;
92 LUA_ENTRY; 92 LUA_LOCK;
93 p = luaA_index(L, index); 93 p = luaA_index(L, index);
94 while (++p < L->top) setobj(p-1, p); 94 while (++p < L->top) setobj(p-1, p);
95 L->top--; 95 L->top--;
96 LUA_EXIT; 96 LUA_UNLOCK;
97} 97}
98 98
99 99
100LUA_API void lua_insert (lua_State *L, int index) { 100LUA_API void lua_insert (lua_State *L, int index) {
101 StkId p; 101 StkId p;
102 StkId q; 102 StkId q;
103 LUA_ENTRY; 103 LUA_LOCK;
104 p = luaA_index(L, index); 104 p = luaA_index(L, index);
105 for (q = L->top; q>p; q--) setobj(q, q-1); 105 for (q = L->top; q>p; q--) setobj(q, q-1);
106 setobj(p, L->top); 106 setobj(p, L->top);
107 LUA_EXIT; 107 LUA_UNLOCK;
108} 108}
109 109
110 110
111LUA_API void lua_pushvalue (lua_State *L, int index) { 111LUA_API void lua_pushvalue (lua_State *L, int index) {
112 LUA_ENTRY; 112 LUA_LOCK;
113 setobj(L->top, luaA_index(L, index)); 113 setobj(L->top, luaA_index(L, index));
114 api_incr_top(L); 114 api_incr_top(L);
115 LUA_EXIT; 115 LUA_UNLOCK;
116} 116}
117 117
118 118
@@ -125,19 +125,19 @@ LUA_API void lua_pushvalue (lua_State *L, int index) {
125LUA_API int lua_type (lua_State *L, int index) { 125LUA_API int lua_type (lua_State *L, int index) {
126 StkId o; 126 StkId o;
127 int i; 127 int i;
128 LUA_ENTRY; 128 LUA_LOCK;
129 o = luaA_indexAcceptable(L, index); 129 o = luaA_indexAcceptable(L, index);
130 i = (o == NULL) ? LUA_TNONE : ttype(o); 130 i = (o == NULL) ? LUA_TNONE : ttype(o);
131 LUA_EXIT; 131 LUA_UNLOCK;
132 return i; 132 return i;
133} 133}
134 134
135 135
136LUA_API const char *lua_typename (lua_State *L, int t) { 136LUA_API const char *lua_typename (lua_State *L, int t) {
137 const char *s; 137 const char *s;
138 LUA_ENTRY; 138 LUA_LOCK;
139 s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t); 139 s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t);
140 LUA_EXIT; 140 LUA_UNLOCK;
141 return s; 141 return s;
142} 142}
143 143
@@ -145,10 +145,10 @@ LUA_API const char *lua_typename (lua_State *L, int t) {
145LUA_API const char *lua_xtype (lua_State *L, int index) { 145LUA_API const char *lua_xtype (lua_State *L, int index) {
146 StkId o; 146 StkId o;
147 const char *type; 147 const char *type;
148 LUA_ENTRY; 148 LUA_LOCK;
149 o = luaA_indexAcceptable(L, index); 149 o = luaA_indexAcceptable(L, index);
150 type = (o == NULL) ? "no value" : luaT_typename(G(L), o); 150 type = (o == NULL) ? "no value" : luaT_typename(G(L), o);
151 LUA_EXIT; 151 LUA_UNLOCK;
152 return type; 152 return type;
153} 153}
154 154
@@ -156,20 +156,20 @@ LUA_API const char *lua_xtype (lua_State *L, int index) {
156LUA_API int lua_iscfunction (lua_State *L, int index) { 156LUA_API int lua_iscfunction (lua_State *L, int index) {
157 StkId o; 157 StkId o;
158 int i; 158 int i;
159 LUA_ENTRY; 159 LUA_LOCK;
160 o = luaA_indexAcceptable(L, index); 160 o = luaA_indexAcceptable(L, index);
161 i = (o == NULL) ? 0 : iscfunction(o); 161 i = (o == NULL) ? 0 : iscfunction(o);
162 LUA_EXIT; 162 LUA_UNLOCK;
163 return i; 163 return i;
164} 164}
165 165
166LUA_API int lua_isnumber (lua_State *L, int index) { 166LUA_API int lua_isnumber (lua_State *L, int index) {
167 TObject *o; 167 TObject *o;
168 int i; 168 int i;
169 LUA_ENTRY; 169 LUA_LOCK;
170 o = luaA_indexAcceptable(L, index); 170 o = luaA_indexAcceptable(L, index);
171 i = (o == NULL) ? 0 : (tonumber(o) == 0); 171 i = (o == NULL) ? 0 : (tonumber(o) == 0);
172 LUA_EXIT; 172 LUA_UNLOCK;
173 return i; 173 return i;
174} 174}
175 175
@@ -182,34 +182,34 @@ LUA_API int lua_isstring (lua_State *L, int index) {
182LUA_API int lua_tag (lua_State *L, int index) { 182LUA_API int lua_tag (lua_State *L, int index) {
183 StkId o; 183 StkId o;
184 int i; 184 int i;
185 LUA_ENTRY; 185 LUA_LOCK;
186 o = luaA_indexAcceptable(L, index); 186 o = luaA_indexAcceptable(L, index);
187 i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); 187 i = (o == NULL) ? LUA_NOTAG : luaT_tag(o);
188 LUA_EXIT; 188 LUA_UNLOCK;
189 return i; 189 return i;
190} 190}
191 191
192LUA_API int lua_equal (lua_State *L, int index1, int index2) { 192LUA_API int lua_equal (lua_State *L, int index1, int index2) {
193 StkId o1, o2; 193 StkId o1, o2;
194 int i; 194 int i;
195 LUA_ENTRY; 195 LUA_LOCK;
196 o1 = luaA_indexAcceptable(L, index1); 196 o1 = luaA_indexAcceptable(L, index1);
197 o2 = luaA_indexAcceptable(L, index2); 197 o2 = luaA_indexAcceptable(L, index2);
198 i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ 198 i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */
199 : luaO_equalObj(o1, o2); 199 : luaO_equalObj(o1, o2);
200 LUA_EXIT; 200 LUA_UNLOCK;
201 return i; 201 return i;
202} 202}
203 203
204LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { 204LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
205 StkId o1, o2; 205 StkId o1, o2;
206 int i; 206 int i;
207 LUA_ENTRY; 207 LUA_LOCK;
208 o1 = luaA_indexAcceptable(L, index1); 208 o1 = luaA_indexAcceptable(L, index1);
209 o2 = luaA_indexAcceptable(L, index2); 209 o2 = luaA_indexAcceptable(L, index2);
210 i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ 210 i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */
211 : luaV_lessthan(L, o1, o2, L->top); 211 : luaV_lessthan(L, o1, o2, L->top);
212 LUA_EXIT; 212 LUA_UNLOCK;
213 return i; 213 return i;
214} 214}
215 215
@@ -218,58 +218,58 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
218LUA_API lua_Number lua_tonumber (lua_State *L, int index) { 218LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
219 StkId o; 219 StkId o;
220 lua_Number n; 220 lua_Number n;
221 LUA_ENTRY; 221 LUA_LOCK;
222 o = luaA_indexAcceptable(L, index); 222 o = luaA_indexAcceptable(L, index);
223 n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); 223 n = (o == NULL || tonumber(o)) ? 0 : nvalue(o);
224 LUA_EXIT; 224 LUA_UNLOCK;
225 return n; 225 return n;
226} 226}
227 227
228LUA_API const char *lua_tostring (lua_State *L, int index) { 228LUA_API const char *lua_tostring (lua_State *L, int index) {
229 StkId o; 229 StkId o;
230 const char *s; 230 const char *s;
231 LUA_ENTRY; 231 LUA_LOCK;
232 o = luaA_indexAcceptable(L, index); 232 o = luaA_indexAcceptable(L, index);
233 s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); 233 s = (o == NULL || tostring(L, o)) ? NULL : svalue(o);
234 LUA_EXIT; 234 LUA_UNLOCK;
235 return s; 235 return s;
236} 236}
237 237
238LUA_API size_t lua_strlen (lua_State *L, int index) { 238LUA_API size_t lua_strlen (lua_State *L, int index) {
239 StkId o; 239 StkId o;
240 size_t l; 240 size_t l;
241 LUA_ENTRY; 241 LUA_LOCK;
242 o = luaA_indexAcceptable(L, index); 242 o = luaA_indexAcceptable(L, index);
243 l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; 243 l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len;
244 LUA_EXIT; 244 LUA_UNLOCK;
245 return l; 245 return l;
246} 246}
247 247
248LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { 248LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) {
249 StkId o; 249 StkId o;
250 lua_CFunction f; 250 lua_CFunction f;
251 LUA_ENTRY; 251 LUA_LOCK;
252 o = luaA_indexAcceptable(L, index); 252 o = luaA_indexAcceptable(L, index);
253 f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; 253 f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c;
254 LUA_EXIT; 254 LUA_UNLOCK;
255 return f; 255 return f;
256} 256}
257 257
258LUA_API void *lua_touserdata (lua_State *L, int index) { 258LUA_API void *lua_touserdata (lua_State *L, int index) {
259 StkId o; 259 StkId o;
260 void *p; 260 void *p;
261 LUA_ENTRY; 261 LUA_LOCK;
262 o = luaA_indexAcceptable(L, index); 262 o = luaA_indexAcceptable(L, index);
263 p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : 263 p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL :
264 tsvalue(o)->u.d.value; 264 tsvalue(o)->u.d.value;
265 LUA_EXIT; 265 LUA_UNLOCK;
266 return p; 266 return p;
267} 267}
268 268
269LUA_API const void *lua_topointer (lua_State *L, int index) { 269LUA_API const void *lua_topointer (lua_State *L, int index) {
270 StkId o; 270 StkId o;
271 const void *p; 271 const void *p;
272 LUA_ENTRY; 272 LUA_LOCK;
273 o = luaA_indexAcceptable(L, index); 273 o = luaA_indexAcceptable(L, index);
274 if (o == NULL) p = NULL; 274 if (o == NULL) p = NULL;
275 else { 275 else {
@@ -285,7 +285,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index) {
285 break; 285 break;
286 } 286 }
287 } 287 }
288 LUA_EXIT; 288 LUA_UNLOCK;
289 return p; 289 return p;
290} 290}
291 291
@@ -297,26 +297,26 @@ LUA_API const void *lua_topointer (lua_State *L, int index) {
297 297
298 298
299LUA_API void lua_pushnil (lua_State *L) { 299LUA_API void lua_pushnil (lua_State *L) {
300 LUA_ENTRY; 300 LUA_LOCK;
301 setnilvalue(L->top); 301 setnilvalue(L->top);
302 api_incr_top(L); 302 api_incr_top(L);
303 LUA_EXIT; 303 LUA_UNLOCK;
304} 304}
305 305
306 306
307LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { 307LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
308 LUA_ENTRY; 308 LUA_LOCK;
309 setnvalue(L->top, n); 309 setnvalue(L->top, n);
310 api_incr_top(L); 310 api_incr_top(L);
311 LUA_EXIT; 311 LUA_UNLOCK;
312} 312}
313 313
314 314
315LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { 315LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
316 LUA_ENTRY; 316 LUA_LOCK;
317 setsvalue(L->top, luaS_newlstr(L, s, len)); 317 setsvalue(L->top, luaS_newlstr(L, s, len));
318 api_incr_top(L); 318 api_incr_top(L);
319 LUA_EXIT; 319 LUA_UNLOCK;
320} 320}
321 321
322 322
@@ -329,20 +329,20 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) {
329 329
330 330
331LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { 331LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
332 LUA_ENTRY; 332 LUA_LOCK;
333 luaV_Cclosure(L, fn, n); 333 luaV_Cclosure(L, fn, n);
334 LUA_EXIT; 334 LUA_UNLOCK;
335} 335}
336 336
337 337
338LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { 338LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) {
339 LUA_ENTRY; 339 LUA_LOCK;
340 /* ORDER LUA_T */ 340 /* ORDER LUA_T */
341 if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) 341 if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag)))
342 luaO_verror(L, "invalid tag for a userdata (%d)", tag); 342 luaO_verror(L, "invalid tag for a userdata (%d)", tag);
343 setuvalue(L->top, luaS_createudata(L, u, tag)); 343 setuvalue(L->top, luaS_createudata(L, u, tag));
344 api_incr_top(L); 344 api_incr_top(L);
345 LUA_EXIT; 345 LUA_UNLOCK;
346} 346}
347 347
348 348
@@ -354,58 +354,58 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) {
354 354
355LUA_API void lua_getglobal (lua_State *L, const char *name) { 355LUA_API void lua_getglobal (lua_State *L, const char *name) {
356 StkId top; 356 StkId top;
357 LUA_ENTRY; 357 LUA_LOCK;
358 top = L->top; 358 top = L->top;
359 setobj(top, luaV_getglobal(L, luaS_new(L, name))); 359 setobj(top, luaV_getglobal(L, luaS_new(L, name)));
360 L->top = top; 360 L->top = top;
361 api_incr_top(L); 361 api_incr_top(L);
362 LUA_EXIT; 362 LUA_UNLOCK;
363} 363}
364 364
365 365
366LUA_API void lua_gettable (lua_State *L, int index) { 366LUA_API void lua_gettable (lua_State *L, int index) {
367 StkId t, top; 367 StkId t, top;
368 LUA_ENTRY; 368 LUA_LOCK;
369 t = Index(L, index); 369 t = Index(L, index);
370 top = L->top; 370 top = L->top;
371 setobj(top-1, luaV_gettable(L, t)); 371 setobj(top-1, luaV_gettable(L, t));
372 L->top = top; /* tag method may change top */ 372 L->top = top; /* tag method may change top */
373 LUA_EXIT; 373 LUA_UNLOCK;
374} 374}
375 375
376 376
377LUA_API void lua_rawget (lua_State *L, int index) { 377LUA_API void lua_rawget (lua_State *L, int index) {
378 StkId t; 378 StkId t;
379 LUA_ENTRY; 379 LUA_LOCK;
380 t = Index(L, index); 380 t = Index(L, index);
381 lua_assert(ttype(t) == LUA_TTABLE); 381 lua_assert(ttype(t) == LUA_TTABLE);
382 setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); 382 setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1));
383 LUA_EXIT; 383 LUA_UNLOCK;
384} 384}
385 385
386 386
387LUA_API void lua_rawgeti (lua_State *L, int index, int n) { 387LUA_API void lua_rawgeti (lua_State *L, int index, int n) {
388 StkId o; 388 StkId o;
389 LUA_ENTRY; 389 LUA_LOCK;
390 o = Index(L, index); 390 o = Index(L, index);
391 lua_assert(ttype(o) == LUA_TTABLE); 391 lua_assert(ttype(o) == LUA_TTABLE);
392 setobj(L->top, luaH_getnum(hvalue(o), n)); 392 setobj(L->top, luaH_getnum(hvalue(o), n));
393 api_incr_top(L); 393 api_incr_top(L);
394 LUA_EXIT; 394 LUA_UNLOCK;
395} 395}
396 396
397 397
398LUA_API void lua_getglobals (lua_State *L) { 398LUA_API void lua_getglobals (lua_State *L) {
399 LUA_ENTRY; 399 LUA_LOCK;
400 sethvalue(L->top, L->gt); 400 sethvalue(L->top, L->gt);
401 api_incr_top(L); 401 api_incr_top(L);
402 LUA_EXIT; 402 LUA_UNLOCK;
403} 403}
404 404
405 405
406LUA_API int lua_getref (lua_State *L, int ref) { 406LUA_API int lua_getref (lua_State *L, int ref) {
407 int status = 1; 407 int status = 1;
408 LUA_ENTRY; 408 LUA_LOCK;
409 if (ref == LUA_REFNIL) { 409 if (ref == LUA_REFNIL) {
410 setnilvalue(L->top); 410 setnilvalue(L->top);
411 api_incr_top(L); 411 api_incr_top(L);
@@ -417,16 +417,16 @@ LUA_API int lua_getref (lua_State *L, int ref) {
417 } 417 }
418 else 418 else
419 status = 0; 419 status = 0;
420 LUA_EXIT; 420 LUA_UNLOCK;
421 return status; 421 return status;
422} 422}
423 423
424 424
425LUA_API void lua_newtable (lua_State *L) { 425LUA_API void lua_newtable (lua_State *L) {
426 LUA_ENTRY; 426 LUA_LOCK;
427 sethvalue(L->top, luaH_new(L, 0)); 427 sethvalue(L->top, luaH_new(L, 0));
428 api_incr_top(L); 428 api_incr_top(L);
429 LUA_EXIT; 429 LUA_UNLOCK;
430} 430}
431 431
432 432
@@ -438,60 +438,60 @@ LUA_API void lua_newtable (lua_State *L) {
438 438
439LUA_API void lua_setglobal (lua_State *L, const char *name) { 439LUA_API void lua_setglobal (lua_State *L, const char *name) {
440 StkId top; 440 StkId top;
441 LUA_ENTRY; 441 LUA_LOCK;
442 top = L->top; 442 top = L->top;
443 luaV_setglobal(L, luaS_new(L, name)); 443 luaV_setglobal(L, luaS_new(L, name));
444 L->top = top-1; /* remove element from the top */ 444 L->top = top-1; /* remove element from the top */
445 LUA_EXIT; 445 LUA_UNLOCK;
446} 446}
447 447
448 448
449LUA_API void lua_settable (lua_State *L, int index) { 449LUA_API void lua_settable (lua_State *L, int index) {
450 StkId t, top; 450 StkId t, top;
451 LUA_ENTRY; 451 LUA_LOCK;
452 t = Index(L, index); 452 t = Index(L, index);
453 top = L->top; 453 top = L->top;
454 luaV_settable(L, t, top-2); 454 luaV_settable(L, t, top-2);
455 L->top = top-2; /* pop index and value */ 455 L->top = top-2; /* pop index and value */
456 LUA_EXIT; 456 LUA_UNLOCK;
457} 457}
458 458
459 459
460LUA_API void lua_rawset (lua_State *L, int index) { 460LUA_API void lua_rawset (lua_State *L, int index) {
461 StkId t; 461 StkId t;
462 LUA_ENTRY; 462 LUA_LOCK;
463 t = Index(L, index); 463 t = Index(L, index);
464 lua_assert(ttype(t) == LUA_TTABLE); 464 lua_assert(ttype(t) == LUA_TTABLE);
465 setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); 465 setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1));
466 L->top -= 2; 466 L->top -= 2;
467 LUA_EXIT; 467 LUA_UNLOCK;
468} 468}
469 469
470 470
471LUA_API void lua_rawseti (lua_State *L, int index, int n) { 471LUA_API void lua_rawseti (lua_State *L, int index, int n) {
472 StkId o; 472 StkId o;
473 LUA_ENTRY; 473 LUA_LOCK;
474 o = Index(L, index); 474 o = Index(L, index);
475 lua_assert(ttype(o) == LUA_TTABLE); 475 lua_assert(ttype(o) == LUA_TTABLE);
476 setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); 476 setobj(luaH_setnum(L, hvalue(o), n), (L->top-1));
477 L->top--; 477 L->top--;
478 LUA_EXIT; 478 LUA_UNLOCK;
479} 479}
480 480
481 481
482LUA_API void lua_setglobals (lua_State *L) { 482LUA_API void lua_setglobals (lua_State *L) {
483 StkId newtable; 483 StkId newtable;
484 LUA_ENTRY; 484 LUA_LOCK;
485 newtable = --L->top; 485 newtable = --L->top;
486 lua_assert(ttype(newtable) == LUA_TTABLE); 486 lua_assert(ttype(newtable) == LUA_TTABLE);
487 L->gt = hvalue(newtable); 487 L->gt = hvalue(newtable);
488 LUA_EXIT; 488 LUA_UNLOCK;
489} 489}
490 490
491 491
492LUA_API int lua_ref (lua_State *L, int lock) { 492LUA_API int lua_ref (lua_State *L, int lock) {
493 int ref; 493 int ref;
494 LUA_ENTRY; 494 LUA_LOCK;
495 if (ttype(L->top-1) == LUA_TNIL) 495 if (ttype(L->top-1) == LUA_TNIL)
496 ref = LUA_REFNIL; 496 ref = LUA_REFNIL;
497 else { 497 else {
@@ -508,7 +508,7 @@ LUA_API int lua_ref (lua_State *L, int lock) {
508 G(L)->refArray[ref].st = lock ? LOCK : HOLD; 508 G(L)->refArray[ref].st = lock ? LOCK : HOLD;
509 } 509 }
510 L->top--; 510 L->top--;
511 LUA_EXIT; 511 LUA_UNLOCK;
512 return ref; 512 return ref;
513} 513}
514 514
@@ -519,9 +519,9 @@ LUA_API int lua_ref (lua_State *L, int lock) {
519*/ 519*/
520 520
521LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { 521LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) {
522 LUA_ENTRY; 522 LUA_LOCK;
523 luaD_call(L, L->top-(nargs+1), nresults); 523 luaD_call(L, L->top-(nargs+1), nresults);
524 LUA_EXIT; 524 LUA_UNLOCK;
525} 525}
526 526
527 527
@@ -535,28 +535,28 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) {
535 535
536LUA_API int lua_getgcthreshold (lua_State *L) { 536LUA_API int lua_getgcthreshold (lua_State *L) {
537 int threshold; 537 int threshold;
538 LUA_ENTRY; 538 LUA_LOCK;
539 threshold = GCscale(G(L)->GCthreshold); 539 threshold = GCscale(G(L)->GCthreshold);
540 LUA_EXIT; 540 LUA_UNLOCK;
541 return threshold; 541 return threshold;
542} 542}
543 543
544LUA_API int lua_getgccount (lua_State *L) { 544LUA_API int lua_getgccount (lua_State *L) {
545 int count; 545 int count;
546 LUA_ENTRY; 546 LUA_LOCK;
547 count = GCscale(G(L)->nblocks); 547 count = GCscale(G(L)->nblocks);
548 LUA_EXIT; 548 LUA_UNLOCK;
549 return count; 549 return count;
550} 550}
551 551
552LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { 552LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
553 LUA_ENTRY; 553 LUA_LOCK;
554 if (newthreshold > GCscale(ULONG_MAX)) 554 if (newthreshold > GCscale(ULONG_MAX))
555 G(L)->GCthreshold = ULONG_MAX; 555 G(L)->GCthreshold = ULONG_MAX;
556 else 556 else
557 G(L)->GCthreshold = GCunscale(newthreshold); 557 G(L)->GCthreshold = GCunscale(newthreshold);
558 luaC_checkGC(L); 558 luaC_checkGC(L);
559 LUA_EXIT; 559 LUA_UNLOCK;
560} 560}
561 561
562 562
@@ -566,7 +566,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
566 566
567LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { 567LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
568 int tag; 568 int tag;
569 LUA_ENTRY; 569 LUA_LOCK;
570 if (basictype != LUA_TNONE && 570 if (basictype != LUA_TNONE &&
571 basictype != LUA_TTABLE && 571 basictype != LUA_TTABLE &&
572 basictype != LUA_TUSERDATA) 572 basictype != LUA_TUSERDATA)
@@ -574,7 +574,7 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
574 tag = luaT_newtag(L, name, basictype); 574 tag = luaT_newtag(L, name, basictype);
575 if (tag == LUA_TNONE) 575 if (tag == LUA_TNONE)
576 luaO_verror(L, "type name '%.30s' already exists", name); 576 luaO_verror(L, "type name '%.30s' already exists", name);
577 LUA_EXIT; 577 LUA_UNLOCK;
578 return tag; 578 return tag;
579} 579}
580 580
@@ -582,22 +582,22 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) {
582LUA_API int lua_type2tag (lua_State *L, const char *name) { 582LUA_API int lua_type2tag (lua_State *L, const char *name) {
583 int tag; 583 int tag;
584 const TObject *v; 584 const TObject *v;
585 LUA_ENTRY; 585 LUA_LOCK;
586 v = luaH_getstr(G(L)->type2tag, luaS_new(L, name)); 586 v = luaH_getstr(G(L)->type2tag, luaS_new(L, name));
587 if (ttype(v) == LUA_TNIL) 587 if (ttype(v) == LUA_TNIL)
588 tag = LUA_TNONE; 588 tag = LUA_TNONE;
589 else { 589 else {
590 lua_assert(ttype(v) == LUA_TNUMBER); 590 lua_assert(ttype(v) == LUA_TNUMBER);
591 tag = nvalue(v); 591 tag = (int)nvalue(v);
592 } 592 }
593 LUA_EXIT; 593 LUA_UNLOCK;
594 return tag; 594 return tag;
595} 595}
596 596
597 597
598LUA_API void lua_settag (lua_State *L, int tag) { 598LUA_API void lua_settag (lua_State *L, int tag) {
599 int basictype; 599 int basictype;
600 LUA_ENTRY; 600 LUA_LOCK;
601 if (tag < 0 || tag >= G(L)->ntag) 601 if (tag < 0 || tag >= G(L)->ntag)
602 luaO_verror(L, "%d is not a valid tag", tag); 602 luaO_verror(L, "%d is not a valid tag", tag);
603 basictype = G(L)->TMtable[tag].basictype; 603 basictype = G(L)->TMtable[tag].basictype;
@@ -615,25 +615,25 @@ LUA_API void lua_settag (lua_State *L, int tag) {
615 luaO_verror(L, "cannot change the tag of a %.20s", 615 luaO_verror(L, "cannot change the tag of a %.20s",
616 luaT_typename(G(L), L->top-1)); 616 luaT_typename(G(L), L->top-1));
617 } 617 }
618 LUA_EXIT; 618 LUA_UNLOCK;
619} 619}
620 620
621 621
622LUA_API void lua_error (lua_State *L, const char *s) { 622LUA_API void lua_error (lua_State *L, const char *s) {
623 LUA_ENTRY; 623 LUA_LOCK;
624 luaD_error(L, s); 624 luaD_error(L, s);
625 LUA_EXIT; 625 LUA_UNLOCK;
626} 626}
627 627
628 628
629LUA_API void lua_unref (lua_State *L, int ref) { 629LUA_API void lua_unref (lua_State *L, int ref) {
630 LUA_ENTRY; 630 LUA_LOCK;
631 if (ref >= 0) { 631 if (ref >= 0) {
632 lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); 632 lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0);
633 G(L)->refArray[ref].st = G(L)->refFree; 633 G(L)->refArray[ref].st = G(L)->refFree;
634 G(L)->refFree = ref; 634 G(L)->refFree = ref;
635 } 635 }
636 LUA_EXIT; 636 LUA_UNLOCK;
637} 637}
638 638
639 639
@@ -641,7 +641,7 @@ LUA_API int lua_next (lua_State *L, int index) {
641 StkId t; 641 StkId t;
642 Node *n; 642 Node *n;
643 int more; 643 int more;
644 LUA_ENTRY; 644 LUA_LOCK;
645 t = luaA_index(L, index); 645 t = luaA_index(L, index);
646 lua_assert(ttype(t) == LUA_TTABLE); 646 lua_assert(ttype(t) == LUA_TTABLE);
647 n = luaH_next(L, hvalue(t), luaA_index(L, -1)); 647 n = luaH_next(L, hvalue(t), luaA_index(L, -1));
@@ -655,7 +655,7 @@ LUA_API int lua_next (lua_State *L, int index) {
655 L->top -= 1; /* remove key */ 655 L->top -= 1; /* remove key */
656 more = 0; 656 more = 0;
657 } 657 }
658 LUA_EXIT; 658 LUA_UNLOCK;
659 return more; 659 return more;
660} 660}
661 661
@@ -664,7 +664,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
664 Hash *h; 664 Hash *h;
665 const TObject *value; 665 const TObject *value;
666 int n; 666 int n;
667 LUA_ENTRY; 667 LUA_LOCK;
668 h = hvalue(luaA_index(L, index)); 668 h = hvalue(luaA_index(L, index));
669 value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ 669 value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */
670 if (ttype(value) == LUA_TNUMBER) 670 if (ttype(value) == LUA_TNUMBER)
@@ -682,31 +682,31 @@ LUA_API int lua_getn (lua_State *L, int index) {
682 } 682 }
683 n = (int)max; 683 n = (int)max;
684 } 684 }
685 LUA_EXIT; 685 LUA_UNLOCK;
686 return n; 686 return n;
687} 687}
688 688
689 689
690LUA_API void lua_concat (lua_State *L, int n) { 690LUA_API void lua_concat (lua_State *L, int n) {
691 StkId top; 691 StkId top;
692 LUA_ENTRY; 692 LUA_LOCK;
693 top = L->top; 693 top = L->top;
694 luaV_strconc(L, n, top); 694 luaV_strconc(L, n, top);
695 L->top = top-(n-1); 695 L->top = top-(n-1);
696 luaC_checkGC(L); 696 luaC_checkGC(L);
697 LUA_EXIT; 697 LUA_UNLOCK;
698} 698}
699 699
700 700
701LUA_API void *lua_newuserdata (lua_State *L, size_t size) { 701LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
702 TString *ts; 702 TString *ts;
703 void *p; 703 void *p;
704 LUA_ENTRY; 704 LUA_LOCK;
705 ts = luaS_newudata(L, size, NULL); 705 ts = luaS_newudata(L, size, NULL);
706 setuvalue(L->top, ts); 706 setuvalue(L->top, ts);
707 api_incr_top(L); 707 api_incr_top(L);
708 p = ts->u.d.value; 708 p = ts->u.d.value;
709 LUA_EXIT; 709 LUA_UNLOCK;
710 return p; 710 return p;
711} 711}
712 712