Skip to content

Commit

Permalink
Make third argument to table.slice optional
Browse files Browse the repository at this point in the history
  • Loading branch information
well-in-that-case committed Oct 25, 2024
1 parent 3e5b39b commit b0faf15
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ltablib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,11 @@ static int tcountvalues (lua_State *L) {
static int tslice (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);

lua_Integer idx_start = luaL_checkinteger(L, 2);
lua_Integer idx_end = luaL_checkinteger(L, 3);
const lua_Integer l = luaL_len(L, 1);

lua_Integer idx_start = luaL_checkinteger(L, 2);
lua_Integer idx_end = luaL_optinteger(L, 3, l);

if (idx_start < 0) {
idx_start = l + idx_start + 1;
}
Expand Down

0 comments on commit b0faf15

Please sign in to comment.