diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-19 11:20:30 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-19 11:20:30 -0200 |
commit | 4ac58853dc820127a11a14ed8bde1fae9458369e (patch) | |
tree | e8179692c97e935ba921c8ebd17abf9c8510d89e /lapi.c | |
parent | f2c451d7455aad3496f32dfa2bfca7f7e8b5376d (diff) | |
download | lua-4ac58853dc820127a11a14ed8bde1fae9458369e.tar.gz lua-4ac58853dc820127a11a14ed8bde1fae9458369e.tar.bz2 lua-4ac58853dc820127a11a14ed8bde1fae9458369e.zip |
thead-specific state separated from "global" state
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.116 2001/01/10 18:56:11 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.117 2001/01/18 15:59:09 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 | */ |
@@ -230,7 +230,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
230 | 230 | ||
231 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | 231 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { |
232 | /* ORDER LUA_T */ | 232 | /* ORDER LUA_T */ |
233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) | 233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) |
234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
235 | setuvalue(L->top, luaS_createudata(L, u, tag)); | 235 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
236 | api_incr_top(L); | 236 | api_incr_top(L); |
@@ -261,14 +261,14 @@ LUA_API void lua_gettable (lua_State *L, int index) { | |||
261 | 261 | ||
262 | LUA_API void lua_rawget (lua_State *L, int index) { | 262 | LUA_API void lua_rawget (lua_State *L, int index) { |
263 | StkId t = Index(L, index); | 263 | StkId t = Index(L, index); |
264 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 264 | lua_assert(ttype(t) == LUA_TTABLE); |
265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
270 | StkId o = Index(L, index); | 270 | StkId o = Index(L, index); |
271 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 271 | lua_assert(ttype(o) == LUA_TTABLE); |
272 | setobj(L->top, luaH_getnum(hvalue(o), n)); | 272 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
273 | api_incr_top(L); | 273 | api_incr_top(L); |
274 | } | 274 | } |
@@ -284,9 +284,9 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
284 | if (ref == LUA_REFNIL) { | 284 | if (ref == LUA_REFNIL) { |
285 | setnilvalue(L->top); | 285 | setnilvalue(L->top); |
286 | } | 286 | } |
287 | else if (0 <= ref && ref < L->nref && | 287 | else if (0 <= ref && ref < G(L)->nref && |
288 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) { | 288 | (G(L)->refArray[ref].st == LOCK || G(L)->refArray[ref].st == HOLD)) { |
289 | setobj(L->top, &L->refArray[ref].o); | 289 | setobj(L->top, &G(L)->refArray[ref].o); |
290 | } | 290 | } |
291 | else | 291 | else |
292 | return 0; | 292 | return 0; |
@@ -324,7 +324,7 @@ LUA_API void lua_settable (lua_State *L, int index) { | |||
324 | 324 | ||
325 | LUA_API void lua_rawset (lua_State *L, int index) { | 325 | LUA_API void lua_rawset (lua_State *L, int index) { |
326 | StkId t = Index(L, index); | 326 | StkId t = Index(L, index); |
327 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 327 | lua_assert(ttype(t) == LUA_TTABLE); |
328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); | 328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
329 | L->top -= 2; | 329 | L->top -= 2; |
330 | } | 330 | } |
@@ -332,7 +332,7 @@ LUA_API void lua_rawset (lua_State *L, int index) { | |||
332 | 332 | ||
333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
334 | StkId o = Index(L, index); | 334 | StkId o = Index(L, index); |
335 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 335 | lua_assert(ttype(o) == LUA_TTABLE); |
336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); | 336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
337 | L->top--; | 337 | L->top--; |
338 | } | 338 | } |
@@ -340,7 +340,7 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) { | |||
340 | 340 | ||
341 | LUA_API void lua_setglobals (lua_State *L) { | 341 | LUA_API void lua_setglobals (lua_State *L) { |
342 | StkId newtable = --L->top; | 342 | StkId newtable = --L->top; |
343 | LUA_ASSERT(ttype(newtable) == LUA_TTABLE, "table expected"); | 343 | lua_assert(ttype(newtable) == LUA_TTABLE); |
344 | L->gt = hvalue(newtable); | 344 | L->gt = hvalue(newtable); |
345 | } | 345 | } |
346 | 346 | ||
@@ -350,17 +350,17 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
350 | if (ttype(L->top-1) == LUA_TNIL) | 350 | if (ttype(L->top-1) == LUA_TNIL) |
351 | ref = LUA_REFNIL; | 351 | ref = LUA_REFNIL; |
352 | else { | 352 | else { |
353 | if (L->refFree != NONEXT) { /* is there a free place? */ | 353 | if (G(L)->refFree != NONEXT) { /* is there a free place? */ |
354 | ref = L->refFree; | 354 | ref = G(L)->refFree; |
355 | L->refFree = L->refArray[ref].st; | 355 | G(L)->refFree = G(L)->refArray[ref].st; |
356 | } | 356 | } |
357 | else { /* no more free places */ | 357 | else { /* no more free places */ |
358 | luaM_growvector(L, L->refArray, L->nref, L->sizeref, struct Ref, | 358 | luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref, |
359 | MAX_INT, "reference table overflow"); | 359 | MAX_INT, "reference table overflow"); |
360 | ref = L->nref++; | 360 | ref = G(L)->nref++; |
361 | } | 361 | } |
362 | setobj(&L->refArray[ref].o, L->top-1); | 362 | setobj(&G(L)->refArray[ref].o, L->top-1); |
363 | L->refArray[ref].st = lock ? LOCK : HOLD; | 363 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; |
364 | } | 364 | } |
365 | L->top--; | 365 | L->top--; |
366 | return ref; | 366 | return ref; |
@@ -386,18 +386,18 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
386 | #define GCunscale(x) ((mem_int)(x)<<10) | 386 | #define GCunscale(x) ((mem_int)(x)<<10) |
387 | 387 | ||
388 | LUA_API int lua_getgcthreshold (lua_State *L) { | 388 | LUA_API int lua_getgcthreshold (lua_State *L) { |
389 | return GCscale(L->GCthreshold); | 389 | return GCscale(G(L)->GCthreshold); |
390 | } | 390 | } |
391 | 391 | ||
392 | LUA_API int lua_getgccount (lua_State *L) { | 392 | LUA_API int lua_getgccount (lua_State *L) { |
393 | return GCscale(L->nblocks); | 393 | return GCscale(G(L)->nblocks); |
394 | } | 394 | } |
395 | 395 | ||
396 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | 396 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { |
397 | if (newthreshold > GCscale(ULONG_MAX)) | 397 | if (newthreshold > GCscale(ULONG_MAX)) |
398 | L->GCthreshold = ULONG_MAX; | 398 | G(L)->GCthreshold = ULONG_MAX; |
399 | else | 399 | else |
400 | L->GCthreshold = GCunscale(newthreshold); | 400 | G(L)->GCthreshold = GCunscale(newthreshold); |
401 | luaC_checkGC(L); | 401 | luaC_checkGC(L); |
402 | } | 402 | } |
403 | 403 | ||
@@ -424,9 +424,9 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
424 | 424 | ||
425 | LUA_API void lua_unref (lua_State *L, int ref) { | 425 | LUA_API void lua_unref (lua_State *L, int ref) { |
426 | if (ref >= 0) { | 426 | if (ref >= 0) { |
427 | LUA_ASSERT(ref < L->nref && L->refArray[ref].st < 0, "invalid ref"); | 427 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); |
428 | L->refArray[ref].st = L->refFree; | 428 | G(L)->refArray[ref].st = G(L)->refFree; |
429 | L->refFree = ref; | 429 | G(L)->refFree = ref; |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
@@ -434,7 +434,7 @@ LUA_API void lua_unref (lua_State *L, int ref) { | |||
434 | LUA_API int lua_next (lua_State *L, int index) { | 434 | LUA_API int lua_next (lua_State *L, int index) { |
435 | StkId t = luaA_index(L, index); | 435 | StkId t = luaA_index(L, index); |
436 | Node *n; | 436 | Node *n; |
437 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 437 | lua_assert(ttype(t) == LUA_TTABLE); |
438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
439 | if (n) { | 439 | if (n) { |
440 | setobj(L->top-1, key(n)); | 440 | setobj(L->top-1, key(n)); |