2 local os
= require("os")
3 local io
= require("io")
4 local string = require("string")
5 -- local posix = require("posix")
6 -- local table = require("table")
7 -- local math = require("math")
11 -- local pcall = pcall
12 -- local pairs = pairs
13 -- local package = package
14 -- local require = require
15 local tostring = tostring
16 -- local tonumber = tonumber
17 local setmetatable
= setmetatable
26 setmetatable (o
,history
)
27 history
.__index
= history
38 function history
:add (entry
)
39 if self
.count
< self
.size
then
40 self
.count
= self
.count
+ 1
41 self
.last
= self
.count
42 self
.data
[self
.last
] = entry
44 self
.last
= 1 + (self
.last
% self
.size
)
45 self
.data
[self
.last
] = entry
49 function history
:oldest ()
51 local i
= 1 + ((self
.last
+ self
.size
- self
.count
) % self
.size
)
57 function history
:newest ()
59 return self
.data
[self
.last
]
64 function history
:walk_reverse ()
72 local i
= 1 + (s
.size
+ index
- 1) % s
.size
81 function history
:walk_reverse_unique ()
84 local iterator
= s
:walk_reverse()