diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-09-16 15:22:48 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-09-16 15:22:48 -0300 |
commit | c8c2e06899b0a05d4af0b71ab527a930356dea08 (patch) | |
tree | 67a30efafd0a7b0fffae80da1850509e4938e300 | |
parent | 8dcc6bc5321f12f28c6738b68350e920983101fb (diff) | |
download | lua-c8c2e06899b0a05d4af0b71ab527a930356dea08.tar.gz lua-c8c2e06899b0a05d4af0b71ab527a930356dea08.tar.bz2 lua-c8c2e06899b0a05d4af0b71ab527a930356dea08.zip |
'select' accepts negative indices
-rw-r--r-- | lbaselib.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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 | } |