Skip to content

Remove update() from the L5 lifecycle#28

Draft
triss wants to merge 1 commit into
L5lua:mainfrom
triss:remove-update-callback
Draft

Remove update() from the L5 lifecycle#28
triss wants to merge 1 commit into
L5lua:mainfrom
triss:remove-update-callback

Conversation

@triss

@triss triss commented Jul 23, 2026

Copy link
Copy Markdown

Summary

This is a follow-up to #26. That fix made update() fire strictly after setup(), but it's simpler to remove update() from the lifecycle entirely rather than keep juggling ordering around an optional, Processing-atypical callback.

L5's supported lifecycle is now just:

setup()
draw()
draw()
...

matching Processing/p5.js, rather than:

setup()
update()
draw()
update()
draw()
...

Solution

  • Removed the call to the user's update() callback and its function love.update(dt) wrapper entirely.
  • The per-frame framework bookkeeping that used to live alongside it (mouse position, deltaTime, key, video looping) still needs to run every frame regardless of update()'s existence, so it's been extracted into L5_internal.updateFrameState(dt) - internal plumbing, not a user-facing callback - called unconditionally each frame from love.run's main loop, in the same place love.update(dt) used to be called.
  • No examples in this repo's examples/ directory currently define/reference update(), so this is a clean removal as far as the codebase is concerned.

Caveat: conflicts with the planned noWindow() / headless-mode design

Checked the docs site source (l5lua.org, L5-website-gh-pages) for any documented reliance on update(). reference/noCanvas/index.html documents update() as the required mechanism for headless sketches:

"No code in draw can continue to run without a window. To have code continue to execute, you must add an update() function and place your code there."

with a sample sketch calling noWindow() then defining update() to keep executing.

However, noWindow()/noCanvas() aren't implemented in L5.lua at all currently (confirmed via grep) - it's still an open item in docs/TODO.md ([ ] add noWindow() for headless mode). So that documented example doesn't run today regardless of this change.

That said, this PR removes the only mechanism the docs currently prescribe for keeping a sketch running once noWindow() ships. Whoever implements headless mode will need to either reintroduce some form of update() scoped to that case, or design/document a different way to keep code executing without a window. Flagging so it isn't silently lost - not blocking this PR, but should be considered before/alongside implementing noWindow().

Test plan

  • Confirmed a sketch defining update() no longer has it called at all (state set in update() never takes effect)
  • Confirmed mouseX, mouseY, deltaTime, and key still update correctly every frame via L5_internal.updateFrameState
  • Ran the repo's main.lua example sketch to confirm no regression in normal draw-loop behavior
  • Checked docs site source for other documented reliance on update() - only the (currently non-functional) noCanvas() example, noted above
  • Confirm change doesn't break other examples

update() was an optional, Processing-atypical callback that ran before
draw() each frame. Combined with L5lua#26 (update() firing before setup()
on startup), it's simpler to just drop it from the lifecycle entirely
- L5's supported lifecycle is now setup() then draw(), matching
Processing/p5.js.

The per-frame framework bookkeeping that used to live alongside it
(mouse position, deltaTime, key, video looping) still needs to run
every frame regardless, so it's extracted into
L5_internal.updateFrameState(dt) - internal plumbing, not a user-facing
callback - called unconditionally from love.run's main loop.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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