mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
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:
parent
0c085ad5c1
commit
bebf8d4fca
2
lume.lua
2
lume.lua
@ -157,7 +157,7 @@ end
|
|||||||
|
|
||||||
function lume.slice(t, i, j)
|
function lume.slice(t, i, j)
|
||||||
i = i or 1
|
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 = {}
|
local rtn = {}
|
||||||
for i = math.max(i, 1), math.min(j, #t) do
|
for i = math.max(i, 1), math.min(j, #t) do
|
||||||
rtn[#rtn + 1] = t[i]
|
rtn[#rtn + 1] = t[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user