diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-21 11:47:42 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-21 11:47:42 -0200 |
commit | 053e87314596e48588a929791012def7818ec989 (patch) | |
tree | e5ce2b8bdf03da3dbdac087bf62824b49e7d40f0 /lbaselib.c | |
parent | 9f4211310fcea9ebf08f4884f8665520c1b8d85f (diff) | |
download | lua-053e87314596e48588a929791012def7818ec989.tar.gz lua-053e87314596e48588a929791012def7818ec989.tar.bz2 lua-053e87314596e48588a929791012def7818ec989.zip |
new macro luaL_opt to avoid evaluating defaults when no needed
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.184 2005/10/03 14:36:45 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.185 2005/10/20 11:35:50 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 | */ |
@@ -340,12 +340,10 @@ static int luaB_assert (lua_State *L) { | |||
340 | 340 | ||
341 | 341 | ||
342 | static int luaB_unpack (lua_State *L) { | 342 | static int luaB_unpack (lua_State *L) { |
343 | int i = luaL_optint(L, 2, 1); | 343 | int i, e, n; |
344 | int e = luaL_optint(L, 3, -1); | ||
345 | int n; | ||
346 | luaL_checktype(L, 1, LUA_TTABLE); | 344 | luaL_checktype(L, 1, LUA_TTABLE); |
347 | if (e == -1) | 345 | i = luaL_optint(L, 2, 1); |
348 | e = luaL_getn(L, 1); | 346 | e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); |
349 | n = e - i + 1; /* number of elements */ | 347 | n = e - i + 1; /* number of elements */ |
350 | if (n <= 0) return 0; /* empty range */ | 348 | if (n <= 0) return 0; /* empty range */ |
351 | luaL_checkstack(L, n, "table too big to unpack"); | 349 | luaL_checkstack(L, n, "table too big to unpack"); |