Skip to content

Lua: opt-in hot reload of function bodies - #1543

Merged
Frotty merged 15 commits into
masterfrom
lua-body-hot-reload
Oct 22, 2026
Merged

Frotty merged 15 commits into
masterfrom
lua-body-hot-reload

Conversation

@Frotty

@Frotty Frotty commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Opt-in hot reload of function bodies for Lua maps, behind -luaHotReload. A running map takes a payload from the editor and replaces function bodies in place; globals, objects and the allocator keep their state. Design and limits: docs/LUA_HOT_RELOAD.md.

How it works

  • The script is split into the function bodies and everything else (globals, field stores, class tables, startup code, generated helpers, function names and parameters). The ABI fingerprint is a hash of that rest, of the source identity of each emitted name, and of the compiler version.
  • A payload carries every function whose printed Lua changed, plus the class-table slots bound to it. A change that reaches other bodies (a stack-trace position, an effect-analysis fact) ships those bodies too. Any edit outside the bodies (a new function, global, closure class or specialisation) is rejected with the reasons.
  • A hot-reload build declares no main-chunk locals, since a payload is a separate chunk; that state becomes globals.
  • Payload n goes to CustomMapData\Wurst\hotreload-<n>.pld. The map polls for the next file once a second, in single player only; the file's Lua section puts a marker and the payload in an ability tooltip, and the map checks the fingerprint and version, then installs with load(..., _ENV). __wurst_hotreload_status() and an on-screen message say what became of each payload.
  • On a Lua project, the editor's hot run (-hotstart) builds with -luaHotReload, and wurst.hotreload (-hotreload) writes the next cumulative payload instead of calling JHCR. No run argument has to be edited. -luaHotReload refuses -inline and -opt.
  • The VS Code side (reload on every save during a hot run) is a separate wurst4vscode change.

Evidence

  • Measured on the 3.0.1.24371 client, single player, in a test map built with -luaHotReload: the editor's payload, delivered while the map ran, changed a function called by name (1 → 2) and an override reached through its class table (4 → 40) on objects made before and after the reload. A sibling's override stayed 3, a global kept its value, and the allocator was not reset. The new body answered within 0.5 s of the first check.
  • The same, driven through the language server as VS Code drives it: wurst.hotstartmap, then an edit saved (didChange, didSave) and wurst.hotreload. The request compiled and wrote the payload in 3.7 s, and the running map ran the new bodies 4.5 s after it was ready, with the same results.
  • A matrix of five payloads in one game, with -stacktraces on and the language server driven the same way: one payload editing 15 kinds of body (free function, override, trigger action and periodic callback registered before the reload, both kinds of generics, tuple result, varargs, constructor, ondestroy, a string with quotes/backslash/ü///!, static function); 300 functions at once (a 93.7 KB file, including a function with 210 locals); an undo; a stale, a foreign and a broken payload, all rejected without effect; a new function rejected by the server, then a valid edit. All checks passed; reloads took 3.1 to 7.9 s in the server and applied 5 to 8.5 s after the map was ready.
  • Measured on that client: Preloader never reads a file again after it was rewritten during the game, while a new file is read within 0.5 s; setting a tooltip to "" leaves its text; a tooltip and a preload file each carry 200,000 characters; a thread waiting in TriggerSleepAction through a reload resumes in its old body and calls the new one by name.
  • The game runs found four defects the unit tests had missed, each fixed with a test: function ids printed a type variable with an identity hash; payloads after the first were never read (one rewritten file, now one file per payload); with no payload file the poll took the ability's own tooltip for one; a local added to a body could take a later function's name.
  • With the flag off, the Lua of a large public map is byte-identical to master's, both as built for runs and with -inline -localOptimizations -opt (rechecked after the last change).
  • LuaHotReloadTests (13), RunArgsTests (with the hot run implication), LuaTranslationTests, LuaBackendAuditTests and HotReloadPipelineTests pass locally (Windows only).

Not covered yet

How often a real project's edits are rejected, and its payload sizes and reload times. Multiplayer is not supported: the files are local, so applying them would desync.

-luaHotReload emits a script whose function bodies a payload can replace
while the map runs; state, objects and the allocator are kept. A payload
carries every function whose printed definition changed; an edit outside
the bodies changes the ABI fingerprint and is rejected. The editor side
writes the payload to a preload file which the map polls (single player);
the in-game delivery is unverified, see docs/LUA_HOT_RELOAD.md and its probe.
Without the flag the output is unchanged.
…easured in the game

The id of a function whose signature has a type variable included the IM
printer's identity hash, so two compilations of one map never matched:
types are printed structurally now. A -luaHotReload build leaves its
manifest in _build/luaHotReload, and LuaHotReloadSession's main turns two
manifests into a preload file. Measured on the 3.0.1.24371 client: the
map picked the payload up and ran the replaced bodies, state kept.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-22T18:34:53.329584Z 6632b20 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5fe2cfda3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

-hotstart and -hotreload, which the editor's hot run and hot reload send,
imply -luaHotReload on a Lua project, so no run argument has to be edited.
Measured in the game: Preloader never reads a file again after it was
rewritten during the game, and setting a tooltip to "" leaves its text. So
payload n goes to Wurst\hotreload-<n>.pld, the poll reads each file once in
order, resets the tooltip to a space and only takes text after a marker. A
hot run deletes earlier sessions' files. A hot-reload build names every
function before translating any body, so a new local cannot take a function's
name. The install is protected and the poll records its outcome.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f9b021e29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded63e8b9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 347bdb5ed5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ee8d820d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a522fc1cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 264f7825bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 560d0a17cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77116c1075

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@Frotty
Frotty merged commit 9820e3a into master Oct 22, 2026
2 checks passed
@Frotty
Frotty deleted the lua-body-hot-reload branch October 22, 2026 19:07
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