Created
August 16, 2018 10:22
-
-
Save JlnWntr/2cf0c15073121234b93a88b8517c3e2a to your computer and use it in GitHub Desktop.
Most simple ringbuffer/queue in Lua (5.3.4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_SIZE = 4 | |
Ring = {} | |
function insert(ring, a) | |
table.insert(ring, a) | |
if #ring > MAX_SIZE then | |
table.remove(ring, 1) | |
end | |
end | |
------------------------TEST-------------------------------------------- | |
insert(Ring, 1) | |
insert(Ring, 2) | |
insert(Ring, 3) | |
insert(Ring, 4) | |
insert(Ring, 5) | |
for k,v in pairs(Ring) do | |
print(v) | |
end | |
insert(Ring, 6) | |
insert(Ring, 7) | |
insert(Ring, 8) | |
print() | |
for k,v in pairs(Ring) do | |
print(v) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment