summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-07-11 12:53:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-07-11 12:53:29 -0300
commit3ca9af51a4f060cf2178901a67a21f8269af3224 (patch)
tree4f1bb541280aa8b4960b16d0925eca60adb2b1a8 /lapi.c
parentc7b89dd28097296bbc14d9b47b4cea72514b2b76 (diff)
downloadlua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.gz
lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.bz2
lua-3ca9af51a4f060cf2178901a67a21f8269af3224.zip
emergency garbage collector (core forces a GC when allocation fails)
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/lapi.c b/lapi.c
index 0fa66eb4..e992d27e 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.54 2006/06/02 15:34:00 roberto Exp roberto $ 2** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 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*/
@@ -42,9 +42,6 @@ const char lua_ident[] =
42 42
43#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) 43#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
44 44
45#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
46
47
48 45
49static TValue *index2adr (lua_State *L, int idx) { 46static TValue *index2adr (lua_State *L, int idx) {
50 if (idx > 0) { 47 if (idx > 0) {
@@ -86,12 +83,6 @@ static Table *getcurrenv (lua_State *L) {
86} 83}
87 84
88 85
89void luaA_pushobject (lua_State *L, const TValue *o) {
90 setobj2s(L, L->top, o);
91 api_incr_top(L);
92}
93
94
95LUA_API int lua_checkstack (lua_State *L, int size) { 86LUA_API int lua_checkstack (lua_State *L, int size) {
96 int res; 87 int res;
97 lua_lock(L); 88 lua_lock(L);
@@ -133,19 +124,6 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
133} 124}
134 125
135 126
136LUA_API lua_State *lua_newthread (lua_State *L) {
137 lua_State *L1;
138 lua_lock(L);
139 luaC_checkGC(L);
140 L1 = luaE_newthread(L);
141 setthvalue(L, L->top, L1);
142 api_incr_top(L);
143 lua_unlock(L);
144 luai_userstatethread(L, L1);
145 return L1;
146}
147
148
149 127
150/* 128/*
151** basic stack manipulation 129** basic stack manipulation
@@ -539,13 +517,12 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
539 517
540LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { 518LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
541 StkId t; 519 StkId t;
542 TValue key;
543 lua_lock(L); 520 lua_lock(L);
544 t = index2adr(L, idx); 521 t = index2adr(L, idx);
545 api_checkvalidindex(L, t); 522 api_checkvalidindex(L, t);
546 setsvalue(L, &key, luaS_new(L, k)); 523 setsvalue2s(L, L->top, luaS_new(L, k));
547 luaV_gettable(L, t, &key, L->top);
548 api_incr_top(L); 524 api_incr_top(L);
525 luaV_gettable(L, t, L->top - 1, L->top - 1);
549 lua_unlock(L); 526 lua_unlock(L);
550} 527}
551 528
@@ -572,10 +549,14 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
572 549
573 550
574LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { 551LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
552 Table *t;
575 lua_lock(L); 553 lua_lock(L);
576 luaC_checkGC(L); 554 luaC_checkGC(L);
577 sethvalue(L, L->top, luaH_new(L, narray, nrec)); 555 t = luaH_new(L);
556 sethvalue(L, L->top, t);
578 api_incr_top(L); 557 api_incr_top(L);
558 if (narray > 0 || nrec > 0)
559 luaH_resize(L, t, narray, nrec);
579 lua_unlock(L); 560 lua_unlock(L);
580} 561}
581 562
@@ -652,14 +633,13 @@ LUA_API void lua_settable (lua_State *L, int idx) {
652 633
653LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { 634LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
654 StkId t; 635 StkId t;
655 TValue key;
656 lua_lock(L); 636 lua_lock(L);
657 api_checknelems(L, 1); 637 api_checknelems(L, 1);
658 t = index2adr(L, idx); 638 t = index2adr(L, idx);
659 api_checkvalidindex(L, t); 639 api_checkvalidindex(L, t);
660 setsvalue(L, &key, luaS_new(L, k)); 640 setsvalue2s(L, L->top++, luaS_new(L, k));
661 luaV_settable(L, t, &key, L->top - 1); 641 luaV_settable(L, t, L->top - 1, L->top - 2);
662 L->top--; /* pop value */ 642 L->top -= 2; /* pop value and key */
663 lua_unlock(L); 643 lua_unlock(L);
664} 644}
665 645
@@ -907,7 +887,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
907 break; 887 break;
908 } 888 }
909 case LUA_GCCOLLECT: { 889 case LUA_GCCOLLECT: {
910 luaC_fullgc(L); 890 luaC_fullgc(L, 0);
911 break; 891 break;
912 } 892 }
913 case LUA_GCCOUNT: { 893 case LUA_GCCOUNT: {