Skip to content

Commit 74e55f1

Browse files
committed
Update LibClass.lua
Correct the handling of negative indexes.
1 parent 4b2b53e commit 74e55f1

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Winsh/Libraries/LibClass.lua

+14-14
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,20 @@ do -- Class 'List' (extends partial implementation in C)
194194
self[ip] = v
195195
end
196196
end
197-
function _TID:remove(p1, p2)
198-
T.checkmethod(self, _C)
199-
local t = #self
200-
p1 = T.tonumber(p1 or t)
201-
if p1 < 0 then p1 = t + p1 end
202-
if p1 < 1 or p1 > t then error("Remove: index out of range") end
203-
p2 = T.tonumber(p2 or p1)
204-
if p2 < 0 then p2 = t + p2 end
205-
if p2 < p1 then p2 = p1 end
206-
local d = p2 - p1 + 1
207-
for i=p2+1, t do self[i-d] = self[i] end
208-
for i=t, t-d+1, -1 do self[i] = nil end
209-
end
210-
function _TID:reverse()
197+
function _TID:remove(p1, p2)
198+
T.checkmethod(self, _C)
199+
local t = #self + 1
200+
p1 = T.tonumber(p1 or t-1)
201+
if p1 < 0 then p1 = t + p1 end
202+
if p1 < 1 or p1 >= t then error("Remove: index out of range") end
203+
p2 = T.tonumber(p2 or p1)
204+
if p2 < 0 then p2 = t + p2 end
205+
if p2 < p1 then p2 = p1 end
206+
local d = p2 - p1 + 1
207+
for i=p2+1, t-1 do self[i-d] = self[i] end
208+
for i=t-1, t-d, -1 do self[i] = nil end
209+
end
210+
function _TID:reverse()
211211
T.checkmethod(self, _C)
212212
local e = #self
213213
for i=1, e/2 do

0 commit comments

Comments
 (0)