workshit/src/moonscript/fuckedtail.moon

32 lines
638 B
Plaintext
Raw Normal View History

2015-06-15 23:04:33 +00:00
class Buffer
2015-06-15 23:30:59 +00:00
-- number -> Buffer
-- creates a new Buffer with the given limit number
2015-06-15 23:04:33 +00:00
new: (limit = 5) =>
2015-06-15 23:30:59 +00:00
@limit = limit -- number
@data = {} -- table
2015-06-15 23:04:33 +00:00
2015-06-15 23:30:59 +00:00
-- nil
-- clears all entries in @data if its length is above number @limit
2015-06-15 23:23:02 +00:00
purge: =>
if #@data > @limit
table.remove @data, 1
@purge!
else return
2015-06-15 23:04:33 +00:00
2015-06-15 23:30:59 +00:00
-- anything -> nil
-- adds the given line anything to @data and calls the too long purging function
2015-06-15 23:23:02 +00:00
add: (line) =>
2015-06-15 23:04:33 +00:00
table.insert @data, line
2015-06-15 23:23:02 +00:00
@purge!
2015-06-15 23:04:33 +00:00
2015-06-15 23:23:02 +00:00
with Buffer 5
2015-06-15 23:13:57 +00:00
while true
n = io.read!
if n ~= nil
\add n
else
break
2015-06-15 23:04:33 +00:00
2015-06-15 23:13:57 +00:00
for _, i in pairs .data
print i