feat: ipairs(...) support in Bytearray
This commit is contained in:
parent
d8feff56c0
commit
9169049530
@ -6,3 +6,7 @@ for i=1,10 do
|
|||||||
assert(#arr == i)
|
assert(#arr == i)
|
||||||
assert(arr[i] == 10 - i)
|
assert(arr[i] == 10 - i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i, v in ipairs(arr) do
|
||||||
|
assert(v == 10 - i)
|
||||||
|
end
|
||||||
|
|||||||
@ -119,6 +119,15 @@ local bytearray_mt = {
|
|||||||
end,
|
end,
|
||||||
__gc = function(self)
|
__gc = function(self)
|
||||||
free(self.bytes)
|
free(self.bytes)
|
||||||
|
end,
|
||||||
|
__ipairs = function(self)
|
||||||
|
local i = 0
|
||||||
|
return function()
|
||||||
|
i = i + 1
|
||||||
|
if i <= self.size then
|
||||||
|
return i, self.bytes[i - 1]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user