diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.138 2003/11/11 16:34:17 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.139 2003/12/09 16:55:43 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -186,14 +186,31 @@ static int luaB_rawset (lua_State *L) { | |||
186 | 186 | ||
187 | static int luaB_gcinfo (lua_State *L) { | 187 | static int luaB_gcinfo (lua_State *L) { |
188 | lua_pushinteger(L, lua_getgccount(L)); | 188 | lua_pushinteger(L, lua_getgccount(L)); |
189 | lua_pushinteger(L, lua_getgcthreshold(L)); | 189 | return 1; |
190 | return 2; | ||
191 | } | 190 | } |
192 | 191 | ||
193 | 192 | ||
194 | static int luaB_collectgarbage (lua_State *L) { | 193 | static int luaB_collectgarbage (lua_State *L) { |
195 | lua_setgcthreshold(L, luaL_optint(L, 1, 0)); | 194 | static const char *const opts[] = {"stop", "restart", "collect", "count", |
196 | return 0; | 195 | NULL}; |
196 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, | ||
197 | LUA_GCCOLLECT, LUA_GCCOUNT}; | ||
198 | int o; | ||
199 | int ex; | ||
200 | #if 1 | ||
201 | if (lua_isnumber(L, 1)) { | ||
202 | int v = lua_tointeger(L, 1); | ||
203 | lua_settop(L, 0); | ||
204 | if (v == 0) lua_pushstring(L, "collect"); | ||
205 | else if (v >= 10000) lua_pushstring(L, "stop"); | ||
206 | else lua_pushstring(L, "restart"); | ||
207 | } | ||
208 | #endif | ||
209 | o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); | ||
210 | ex = luaL_optint(L, 2, 0); | ||
211 | luaL_argcheck(L, o >= 0, 1, "invalid option"); | ||
212 | lua_pushinteger(L, lua_gc(L, optsnum[o], ex)); | ||
213 | return 1; | ||
197 | } | 214 | } |
198 | 215 | ||
199 | 216 | ||
@@ -311,10 +328,10 @@ static int luaB_load (lua_State *L) { | |||
311 | 328 | ||
312 | static int luaB_dofile (lua_State *L) { | 329 | static int luaB_dofile (lua_State *L) { |
313 | const char *fname = luaL_optstring(L, 1, NULL); | 330 | const char *fname = luaL_optstring(L, 1, NULL); |
314 | int status = luaL_loadfile(L, fname); | 331 | int n = lua_gettop(L); |
315 | if (status != 0) lua_error(L); | 332 | if (luaL_loadfile(L, fname) != 0) lua_error(L); |
316 | lua_call(L, 0, LUA_MULTRET); | 333 | lua_call(L, 0, LUA_MULTRET); |
317 | return lua_gettop(L) - 1; | 334 | return lua_gettop(L) - n; |
318 | } | 335 | } |
319 | 336 | ||
320 | 337 | ||
@@ -710,6 +727,6 @@ LUALIB_API int luaopen_base (lua_State *L) { | |||
710 | luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0); | 727 | luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0); |
711 | lua_newtable(L); | 728 | lua_newtable(L); |
712 | lua_setglobal(L, REQTAB); | 729 | lua_setglobal(L, REQTAB); |
713 | return 0; | 730 | return 2; |
714 | } | 731 | } |
715 | 732 | ||