Fixed bug with negative j index in lume.slice()

Fixed a bug where giving lume.slice() a negative j index (or no j index)
would not result in the correct slice -- the behaviour now correctly
matches that of string.sub() when passing a negative j index.
This commit is contained in:
rxi 2014-03-03 18:56:12 +00:00
parent 0c085ad5c1
commit bebf8d4fca

View File

@ -157,7 +157,7 @@ end
function lume.slice(t, i, j)
i = i or 1
j = j and (j < 0 and (#t + j) or j) or (#t - i + 1)
j = j and (j < 0 and (#t + j + 1) or j) or #t
local rtn = {}
for i = math.max(i, 1), math.min(j, #t) do
rtn[#rtn + 1] = t[i]