From c4ee12adac3b261d4a3acbc4542c89d1985703f1 Mon Sep 17 00:00:00 2001 From: tangent Date: Mon, 21 Sep 2026 23:05:37 -0600 Subject: [PATCH] Add ReadMe.md --- ReadMe.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ReadMe.md diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..79130a0 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,38 @@ +# timer +Easy timers in Lua. Spiritual successor to kikito's cron.lua + +Public domain! Who needs an IP anyhow? + +## Usage +Can be used as a drop-in replacement for [kikito's cron.lua](https://github.com/kikito/cron.lua), +but that misses the biggest benefit, which is the timer library itself managing +timers, including discarding expired timers: + +```lua +timer.after(time, function, ...) -- runs once after time +timer.every(time, function, ...) -- runs repeatedly, every time + +timer.update(delta) -- increment, run functions, discard expired.. +``` + +A timer can be excluded from `timer.update`, in which case it must be manually +updated: +```lua +local my_timer = timer.every(time, function, ...) +my_timer.manual = true + +my_timer:update(delta) +``` + +`timer.update` returns a table of expired/unexpired timers. Example: +```lua +local my_timer = timer.after(time, function, ...) + +local expired = timer.update(delta) +if expired[my_timer] then + -- idk, whatever you needed +end +``` + +Timers can have their time set to a new value with `my_timer:reset(time)`. If +nothing is passed, they will be set to `0`.