aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-02 11:47:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-02 11:47:43 -0300
commit78bc8e553d4190fc3b90be5b621fc0f3507586ef (patch)
tree9bd9317e1a56960b944549d44a20b91024574c19 /lapi.c
parentdad808a73a98a23729614b8814728d76b4e5d577 (diff)
downloadlua-78bc8e553d4190fc3b90be5b621fc0f3507586ef.tar.gz
lua-78bc8e553d4190fc3b90be5b621fc0f3507586ef.tar.bz2
lua-78bc8e553d4190fc3b90be5b621fc0f3507586ef.zip
new API for garbage collector
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/lapi.c b/lapi.c
index 09ab8f20..f2cd0b0d 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.100 2000/09/27 12:51:39 roberto Exp roberto $ 2** $Id: lapi.c,v 1.101 2000/09/29 12:42:13 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*/
@@ -155,7 +155,6 @@ double lua_tonumber (lua_State *L, int index) {
155} 155}
156 156
157const char *lua_tostring (lua_State *L, int index) { 157const char *lua_tostring (lua_State *L, int index) {
158 luaC_checkGC(L); /* `tostring' may create a new string */
159 access(L, index, (tostring(L, o) == 0), NULL, svalue(o)); 158 access(L, index, (tostring(L, o) == 0), NULL, svalue(o));
160} 159}
161 160
@@ -203,7 +202,6 @@ void lua_pushnumber (lua_State *L, double n) {
203 202
204 203
205void lua_pushlstring (lua_State *L, const char *s, size_t len) { 204void lua_pushlstring (lua_State *L, const char *s, size_t len) {
206 luaC_checkGC(L);
207 tsvalue(L->top) = luaS_newlstr(L, s, len); 205 tsvalue(L->top) = luaS_newlstr(L, s, len);
208 ttype(L->top) = TAG_STRING; 206 ttype(L->top) = TAG_STRING;
209 api_incr_top(L); 207 api_incr_top(L);
@@ -219,13 +217,11 @@ void lua_pushstring (lua_State *L, const char *s) {
219 217
220 218
221void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { 219void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
222 luaC_checkGC(L);
223 luaV_Cclosure(L, fn, n); 220 luaV_Cclosure(L, fn, n);
224} 221}
225 222
226 223
227void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */ 224void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */
228 luaC_checkGC(L);
229 if (tag != LUA_ANYTAG && tag != TAG_USERDATA && tag < NUM_TAGS) 225 if (tag != LUA_ANYTAG && tag != TAG_USERDATA && tag < NUM_TAGS)
230 luaO_verror(L, "invalid tag for a userdata (%d)", tag); 226 luaO_verror(L, "invalid tag for a userdata (%d)", tag);
231 tsvalue(L->top) = luaS_createudata(L, u, tag); 227 tsvalue(L->top) = luaS_createudata(L, u, tag);
@@ -292,7 +288,6 @@ int lua_getref (lua_State *L, int ref) {
292 288
293 289
294void lua_newtable (lua_State *L) { 290void lua_newtable (lua_State *L) {
295 luaC_checkGC(L);
296 hvalue(L->top) = luaH_new(L, 0); 291 hvalue(L->top) = luaH_new(L, 0);
297 ttype(L->top) = TAG_TABLE; 292 ttype(L->top) = TAG_TABLE;
298 api_incr_top(L); 293 api_incr_top(L);
@@ -377,6 +372,31 @@ void lua_rawcall (lua_State *L, int nargs, int nresults) {
377 372
378 373
379/* 374/*
375** Garbage-collection functions
376*/
377
378/* GC values are expressed in Kbytes: #bytes/2^10 */
379#define GCscale(x) ((int)((x)>>10))
380#define GCunscale(x) ((unsigned long)(x)<<10)
381
382int lua_getgcthreshold (lua_State *L) {
383 return GCscale(L->GCthreshold);
384}
385
386int lua_getgccount (lua_State *L) {
387 return GCscale(L->nblocks);
388}
389
390void lua_setgcthreshold (lua_State *L, int newthreshold) {
391 if (newthreshold > GCscale(ULONG_MAX))
392 L->GCthreshold = ULONG_MAX;
393 else
394 L->GCthreshold = GCunscale(newthreshold);
395 luaC_checkGC(L);
396}
397
398
399/*
380** miscellaneous functions 400** miscellaneous functions
381*/ 401*/
382 402
@@ -449,5 +469,6 @@ void lua_concat (lua_State *L, int n) {
449 StkId top = L->top; 469 StkId top = L->top;
450 luaV_strconc(L, n, top); 470 luaV_strconc(L, n, top);
451 L->top = top-(n-1); 471 L->top = top-(n-1);
472 luaC_checkGC(L);
452} 473}
453 474