Skip to content

fix(lua-5.4): 1-arg os.difftime in 6 imported scripts#6

Merged
Aybook merged 1 commit into
masterfrom
fix/lua-5.4-os-difftime-arity
May 6, 2026
Merged

fix(lua-5.4): 1-arg os.difftime in 6 imported scripts#6
Aybook merged 1 commit into
masterfrom
fix/lua-5.4-os-difftime-arity

Conversation

@Aybook
Copy link
Copy Markdown
Contributor

@Aybook Aybook commented May 6, 2026

Sweep of an audit miss. The initial pattern check across PRs #1, #3, and #5 missed the nested-paren form `os.difftime( os.time() - X )` because the regex didn't see through the inner parentheses. The issue surfaced on the announcements batch (#5) and got fixed there for three scripts. This PR closes the rest of the gap on master.

The bug

Pattern: `os_difftime( os_time() - SOMETIME ) >= delay` inside onTimer handlers.

Lua 5.4 strict-checks `os.difftime` arity (must be 2 args). The upstream wrote one expression-arg pattern that reduced to a single number and 5.4 errors at runtime: `bad argument #2 to 'difftime' (number expected, got no value)`.

The smoke harness has been silently passing because its ~5-10s window doesn't always trigger an onTimer firing while the listener is bad-shaped. On a real deploy it would error on the first tick.

Fix

Replaced `os_difftime( os_time() - X )` with the equivalent direct subtraction `(os_time() - X)`. Same pattern that landed in the announcements PR (#5).

Affected files

File Line Source PR
`scripts/cmd_pm2offliners/cmd_pm2offliners.lua` 278 #3
`scripts/etc_banner_mod/etc_banner_mod.lua` 143 #5
`scripts/etc_EventAnnouncer/etc_EventAnnouncer.lua` 160, 180 #5
`scripts/etc_mainecho/etc_mainecho.lua` 121 #1
`scripts/etc_messenger/etc_messenger.lua` 133 #1
`scripts/etc_wunschbrett/etc_wunschbrett.lua` 134 #1

7 occurrences across 6 files. +7 / -7 lines.

Test plan

  • Smoke harness against `luadch-ng/luadch` v3.1.1 with all merged batches plus this fix dropped into the install: 10 / 10 PASS.
  • Multiline-aware audit on all imported scripts confirms no remaining 1-arg `os.difftime` patterns. The only remaining `os.difftime` calls are legitimate 2-arg ones (`ptx_rotatingtopic.lua`, three sites in `ptx_tophubbers.lua`).

Future-proofing

For upcoming import batches I'm using a multiline-aware audit (awk that skips block-comment regions) that walks every `os.difftime` call site and inspects the full arglist between the matched parens, instead of a flat regex.

Sweep of an audit miss. The initial pattern checks across PRs #1, #3,
and #5 didn't catch the nested-paren form os.difftime( os.time() - X )
because the regex couldn't see through the inner parentheses; the
issue surfaced on the announcements batch (#5) and got fixed there
for three scripts. This PR closes the rest of the gap on master.

Pattern: os_difftime( os_time() - SOMETIME ) >= delay inside onTimer
handlers. Lua 5.4 strict-checks os.difftime arity and errors at
runtime; the smoke harness has been silently passing because its
~5-10s window doesn't always trigger an onTimer firing while the
listener is bad-shaped (it would error on first tick on a real
deploy).

Replaced with the equivalent direct subtraction (os_time() - X), same
fix pattern as the announcements batch.

Affected files:

- scripts/cmd_pm2offliners/cmd_pm2offliners.lua:278 (PR #3)
- scripts/etc_banner_mod/etc_banner_mod.lua:143 (PR #5)
- scripts/etc_EventAnnouncer/etc_EventAnnouncer.lua:160, 180 (PR #5)
- scripts/etc_mainecho/etc_mainecho.lua:121 (PR #1)
- scripts/etc_messenger/etc_messenger.lua:133 (PR #1)
- scripts/etc_wunschbrett/etc_wunschbrett.lua:134 (PR #1)

Smoke harness against luadch-ng/luadch v3.1.1: 10 / 10 PASS.

Future-proofing: for upcoming import batches use a multiline-aware
audit that walks all os.difftime call sites and inspects the full
arglist between the matched parens, not a flat regex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant