diff --git a/src/ltablib.cpp b/src/ltablib.cpp index cb7f925b0c..757970dfa4 100644 --- a/src/ltablib.cpp +++ b/src/ltablib.cpp @@ -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; }