aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lbaselib.c b/lbaselib.c
index c3a8cb5e..7bed0bb5 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.153 2004/07/09 16:01:38 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.154 2004/07/09 18:23:17 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*/
@@ -348,15 +348,17 @@ static int luaB_unpack (lua_State *L) {
348 348
349 349
350static int luaB_select (lua_State *L) { 350static int luaB_select (lua_State *L) {
351 int i = luaL_checkint(L, 1);
352 int n = lua_gettop(L); 351 int n = lua_gettop(L);
353 if (i < 0 || i >= n) /* index out of range? */ 352 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
354 return 0;
355 if (i == 0)
356 lua_pushinteger(L, n-1); 353 lua_pushinteger(L, n-1);
357 else 354 return 1;
358 lua_pushvalue(L, i+1); 355 }
359 return 1; 356 else {
357 int i = luaL_checkint(L, 1);
358 if (i <= 0) i = 1;
359 else if (i >= n) i = n;
360 return n - i;
361 }
360} 362}
361 363
362 364