History variables: Difference between revisions

m
Line 1,213:
<lang lua>-- History variables in Lua 6/12/2020 db
local HistoryVariable = {
value = nil, -- nop, for ref only
history = {},
new = function(self)
Line 1,219 ⟶ 1,218:
end,
get = function(self)
return self.valuehistory[#self.history]
end,
set = function(self, value)
self.history[#self.history+1] = value
self.value = value
end,
undo = function(self)
self.value = self.history[#self.history-1]
self.history[#self.history] = nil
end,
Line 1,239 ⟶ 1,236:
hv:set(2); print("set() to:", hv:get())
hv:set(3); print("set() to:", hv:get())
hv:set(nil); print("set() to:", hv:get())
--
print("history:", table.concat(hv.history,","))
Anonymous user