Repository navigation
feat(os): seed os.clock origin at install, add os.time_ms/os.time_us - #340
Merged
Merged
Conversation
Seed boot_offset() during install/1 so os.clock() measures elapsed time from a stable startup point rather than from its first call. Add two non-standard helpers, os.time_ms() and os.time_us(), returning the current epoch in milliseconds and microseconds; os.time() keeps its whole-second PUC-Lua semantics. Closes #330
davydog187
commented
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #330.
Context
Issue #330 flagged two problems with the
osstandard library:os.clock()origin was seeded lazily. Theboot_offset/0helper's comment claimed the monotonic origin was "captured at module load," but it was actually seeded on the first call toos.clock()— so the origin drifted to whenever a program first happened to call it.os.time()returns whole seconds (correct PUC-Lua behavior), leaving programs that need finer resolution with no option.Changes
boot_offset()ininstall/1soos.clock()measures elapsed time from a stable startup point. Updated the staleboot_offset/0comment to describe the real (:persistent_term, BEAM-global, first-installer-wins) semantics.os.time_ms()andos.time_us()— non-standard extensions returning the current epoch in milliseconds / microseconds viaSystem.os_time/1. Both are current-time-only (no date-table arg, since sub-second precision on a whole-second date table is meaningless).os.time()is unchanged.@moduledoclists the new functions and explicitly marks them as extensions not present in PUC-Lua.Tests
Added coverage in
test/lua/vm/stdlib/os_test.exsfor integer type and magnitude of both new functions, plus a cross-check that ms/us trackos.time(). All os tests pass (mix test test/lua/vm/stdlib/os_test.exs→ 12 passed).Out of scope
os.clock()per-VM rather than BEAM-global (issue only asks to seed at install)._ms/_usvariants.os.time()'s whole-second return.