-- Atrapa dla funkcji setLogicValue, aby uniknąć błędów w Intellisense
if not getClock then
function getClock()
-- Pusta implementacja: w docelowym środowisku funkcja istnieje
end
end
-- class definition
Counter =
{
-- time point in floating point cpu seconds
timePoint = nil,
};
Counter.__index = Counter;
-- constructor
function Counter.create()
local cnt = {}; -- our new object
setmetatable(cnt, Counter); -- make Counter handle lookup
-- initialize our object
cnt.timePoint = getClock();
return cnt;
end
-- returns number of milliseconds since last reset.
function Counter:elapsed()
return getClock() - self.timePoint;
end
-- resets counter
function Counter:reset()
self.timePoint = getClock();
end