aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-16 15:22:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-16 15:22:48 -0300
commitc8c2e06899b0a05d4af0b71ab527a930356dea08 (patch)
tree67a30efafd0a7b0fffae80da1850509e4938e300
parent8dcc6bc5321f12f28c6738b68350e920983101fb (diff)
downloadlua-c8c2e06899b0a05d4af0b71ab527a930356dea08.tar.gz
lua-c8c2e06899b0a05d4af0b71ab527a930356dea08.tar.bz2
lua-c8c2e06899b0a05d4af0b71ab527a930356dea08.zip
'select' accepts negative indices
-rw-r--r--lbaselib.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 93391550..219180b6 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.181 2005/08/15 14:12:32 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.182 2005/08/26 17:36:32 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*/
@@ -349,8 +349,9 @@ static int luaB_select (lua_State *L) {
349 } 349 }
350 else { 350 else {
351 int i = luaL_checkint(L, 1); 351 int i = luaL_checkint(L, 1);
352 if (i <= 0) i = 1; 352 if (i < 0) i = n + i;
353 else if (i >= n) i = n; 353 else if (i > n) i = n;
354 luaL_argcheck(L, 1 <= i, 1, "index out of range");
354 return n - i; 355 return n - i;
355 } 356 }
356} 357}