From 78bc8e553d4190fc3b90be5b621fc0f3507586ef Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 2 Oct 2000 11:47:43 -0300 Subject: new API for garbage collector --- lbaselib.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index ee102e36..1a3031ac 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.5 2000/09/14 14:09:31 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.6 2000/09/20 12:54:17 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -183,10 +183,8 @@ static int luaB_settagmethod (lua_State *L) { const char *event = luaL_check_string(L, 2); luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, "function or nil expected"); - lua_pushnil(L); /* to get its tag */ - if (strcmp(event, "gc") == 0 && tag != lua_tag(L, -1)) + if (strcmp(event, "gc") == 0) lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); - lua_pop(L, 1); /* remove the nil */ lua_settagmethod(L, tag, event); return 1; } @@ -197,9 +195,16 @@ static int luaB_gettagmethod (lua_State *L) { } +static int luaB_gcinfo (lua_State *L) { + lua_pushnumber(L, lua_getgccount(L)); + lua_pushnumber(L, lua_getgcthreshold(L)); + return 2; +} + + static int luaB_collectgarbage (lua_State *L) { - lua_pushnumber(L, lua_collectgarbage(L, luaL_opt_int(L, 1, 0))); - return 1; + lua_setgcthreshold(L, luaL_opt_int(L, 1, 0)); + return 0; } @@ -601,6 +606,7 @@ static const struct luaL_reg base_funcs[] = { {"error", luaB_error}, {"foreach", luaB_foreach}, {"foreachi", luaB_foreachi}, + {"gcinfo", luaB_gcinfo}, {"getglobal", luaB_getglobal}, {"gettagmethod", luaB_gettagmethod}, {"globals", luaB_globals}, -- cgit v1.2.3-55-g6feb