From 151b57adc61c309b34deb67403f442067549cd95 Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 13 Mar 2014 21:26:36 +0000 Subject: [PATCH] Fixed behaviour for negative i argument on lume.slice() A negative value for the `i` argument of lume.slice() is now handled properly (used as an index from the end of the string) to mimicing the behaviour of lua's string.sub() --- lume.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lume.lua b/lume.lua index d13f03d..26d8b0f 100644 --- a/lume.lua +++ b/lume.lua @@ -176,8 +176,9 @@ end function lume.slice(t, i, j) - i = i or 1 - j = j and (j < 0 and (#t + j + 1) or j) or #t + local function index(x) return x < 0 and (#t + x + 1) or x end + i = i and index(i) or 1 + j = j and index(j) or #t local rtn = {} for i = math.max(i, 1), math.min(j, #t) do rtn[#rtn + 1] = t[i]