How To Call It
Stopwatch is a callable factory table: object methods are called as watch:<method>(...), and the table’s own functions as Stopwatch.<method>(...).
Measures elapsed time. Stopwatch() creates a stopwatch object; start(), elapsedMs() and lap() are called on that object.
Documented for app version 1.0.51Updated:
Stopwatch is a callable factory table: object methods are called as watch:<method>(...), and the table’s own functions as Stopwatch.<method>(...).
For time flow, combine DateTime, TimeSpan, and Stopwatch with logging, timeout control, and performance measurement.
Stopwatch offers 14 methods; each method page lists its parameters and return value.
A strong combination is to measure with Stopwatch, log with DateTime, and compare durations with TimeSpan.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))local watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))
-- Continue with one focused method on the object.local watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))
local note = "Stopwatch overview loaded"
print(note)-- For time flow, combine DateTime, TimeSpan, and Stopwatch with logging, timeout control, and performance measurement.
local function run_stopwatch_step()
local watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))
end
local ok, err = pcall(run_stopwatch_step)
if not ok then
toast("Step failed")
print(err)
endlocal watch = Stopwatch()
watch:start()
wait(250)
print("Elapsed ms: " .. tostring(watch:elapsedMs()))
print("Elapsed ms: " .. tostring(watch:elapsedMs()))