Skip to content

feat: support Lua and JavaScript extensions#1196

Open
gennaroprota wants to merge 5 commits intocppalliance:developfrom
gennaroprota:feat/support_scripting_extensions
Open

feat: support Lua and JavaScript extensions#1196
gennaroprota wants to merge 5 commits intocppalliance:developfrom
gennaroprota:feat/support_scripting_extensions

Conversation

@gennaroprota
Copy link
Copy Markdown
Collaborator

@gennaroprota gennaroprota commented May 7, 2026

This mirrors the existing JavaScript helpers for Lua and adds support for corpus-mutation extensions written either in Lua or Javascript.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✨ Highlights

  • 🧪 New golden tests added

🧾 Changes by Scope

Scope Lines Δ% Lines Δ Lines + Lines - Files Δ Files + Files ~ Files ↔ Files -
🛠️ Source 54% 1006 954 52 8 2 6 - -
🥇 Golden Tests 35% 662 662 - 43 43 - - -
📄 Docs 9% 172 172 - 3 1 2 - -
🤝 Third-party 2% 31 18 13 1 - 1 - -
Total 100% 1871 1806 65 55 46 9 - -

Legend: Files + (added), Files ~ (modified), Files ↔ (renamed), Files - (removed)

🔝 Top Files

  • src/lib/Extensions/RunExtensions.cpp (Source): 433 lines Δ (+433 / -0)
  • src/lib/Support/Lua.cpp (Source): 276 lines Δ (+268 / -8)
  • src/lib/Gen/hbs/Builder.cpp (Source): 144 lines Δ (+111 / -33)

Generated by 🚫 dangerJS against 2a20121

@gennaroprota gennaroprota force-pushed the feat/support_scripting_extensions branch from ef7ea6b to 2156b1c Compare May 7, 2026 10:42
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.12%. Comparing base (7e73057) to head (2a20121).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1196   +/-   ##
========================================
  Coverage    82.12%   82.12%           
========================================
  Files           33       33           
  Lines         3149     3149           
  Branches       734      734           
========================================
  Hits          2586     2586           
  Misses         387      387           
  Partials       176      176           
Flag Coverage Δ
bootstrap 82.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented May 7, 2026

An automated preview of the documentation is available at https://1196.mrdocs.prtest2.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-05-08 05:23:53 UTC

@gennaroprota gennaroprota changed the title feat(handlebars): support Lua scripts as Handlebars helpers feat(handlebars): support Lua and JavaScript extensions May 7, 2026
@gennaroprota gennaroprota changed the title feat(handlebars): support Lua and JavaScript extensions feat: support Lua and JavaScript extensions May 7, 2026
@gennaroprota gennaroprota force-pushed the feat/support_scripting_extensions branch 2 times, most recently from 63f542c to 8c6f453 Compare May 7, 2026 16:34
This mirrors the existing JS helpers for Lua. *.lua files placed in an
addon's generator/{common|<ext>}/helpers/ directory are auto-registered
as Handlebars helpers; files whose name starts with '_' run first as
utility scripts. Two golden fixtures (lua-helper/, lua-helper-layering/)
mirror their JS counterparts and cover the `addons-supplemental`
override.

Incidental fixes to issues uncovered by this patch:

- Added a qualification to `MRDOCS_TRY` / `MRDOCS_CHECK_*` /
  `MRDOCS_CHECK_OR_*` / `MRDOCS_CHECK_OR_CONTINUE` to make them work
  with nested namespaces named `detail`.

- Dropped onelua.c and ltests.c from the Lua build patch, because the
  former defines `main`, which conflicted with our `main`, and the
  latter is test scaffolding which shouldn't ship in a library build.

- Added `extern "C"` around the Lua includes.
The `__index` metamethod in `domObject_push_metatable()` retrieved the
value correctly via `Object::get(key)`, then called `lua_replace(L, 1)`
to move the result into the userdata's slot. `lua_replace` also pops the
top, so, on return, the key string was at the top of the stack and Lua
picked it up as the metamethod's single return value, making every field
access on a `dom::Object` userdata silently return the key it was asked
for.

This was latent until now because no Lua script in the test suite
previously read fields off a `dom::Object` userdata. Surfaced while
wiring corpus extensions: a script doing `corpus.symbols[i]` saw
`"symbols"` (the key) instead of the array.
This adds a hook that runs user-provided Lua scripts after corpus
extraction and finalization, before any generator runs. Extensions live
in <addon>/extensions/*.lua for each addon root in the configuration. A
script may define `transform_corpus(corpus)`, which is invoked once with
a flat DOM view of the corpus. The script may mutate the corpus by
calling pre-registered globals on the `mrdocs` table; currently:

- `mrdocs.set_brief(symbol_id, text)`: replace a symbol's brief with a
  single-paragraph plain-text block.

Each setter validates its arguments and raises a Lua error on misuse;
any uncaught error in a script aborts the build. Multiple extensions run
in alphabetical order by file path. The mutation surface is
intentionally narrow; additional setters will land as concrete use cases
surface.

A golden fixture (test-files/golden-tests/extensions/lua-set-brief/)
rewrites a function's brief from Lua and verifies the change reaches the
xml output.

Finally, this touches Lua wrapper for two new affordances:
`Scope::pushDom` for the corpus argument, and a `Context::nativeState()`
escape hatch for binding native C functions as Lua globals (the wrapper
doesn't abstract that yet).
This mirrors the Lua corpus-mutation hook for JavaScript. Extension
scripts under <addon>/extensions/*.js can now define
`transform_corpus(corpus)` and call `mrdocs.set_brief(symbol_id, text)`,
just like their Lua counterparts. The Lua and JS bindings now share a
language-agnostic `setBriefImpl` helper that takes already-extracted
`dom::Value` arguments. Each binding is a thin adapter:

- Lua: the existing C closure registered on the raw `lua_State*`.
- JS: a `dom::Function` exposed as a property of a `mrdocs` global
  object; the wrapper's `setGlobal` -> `toJsValue` ->
  `makeFunctionProxy` chain handles the rest.

Discovery picks up both *.lua and *.js, sorted together so script
ordering doesn't depend on the chosen language. A golden fixture mirrors
the Lua test.
@gennaroprota gennaroprota force-pushed the feat/support_scripting_extensions branch from 8c6f453 to 2a20121 Compare May 8, 2026 05:17
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.

2 participants