Macro-generate repetitive Luax getter/setter functions#1
Conversation
Replace 19 hand-written getter/setter functions across 5 groups (maybe-get-*, set-*-global, get-*-global, set-*-field, get-*-field) with defndynamic generators that produce identical code from type specs. Reduces boilerplate by ~50 lines while preserving the same public API, behavior, and documentation.
Build & TestsCI failing on both ubuntu and macOS: Findings
Verdict: reviseCI is failing due to |
defndynamic evaluates arguments, so bare symbols like `int` and `Lua.TYPE_NUMBER` fail with "Can't find symbol". defmacro receives arguments unevaluated, which is what these code generators need.
ReviewBuild & TestsCI passing on both ubuntu-latest and macos-latest. No local Carp compiler available; relying on CI. Prior feedbackThe previous review (2026-05-21) identified that all 5 generators needed FindingsVerified correct:
Minor note: The PR description body still says "5 Verdict: mergeThe |
Summary
Replace 19 hand-written getter/setter functions in the
Luaxmodule with 5defndynamicgenerators (luax--def-maybe-get,luax--def-set-global,luax--def-get-global,luax--def-set-field,luax--def-get-field) that produce identical code from compact type specs.Before: each type variant (int, float, bool, string) × each operation group was a separate
doc/defnpair — 150 lines of near-identical code.After: 5 generators (68 lines) + 19 one-liner invocations (32 lines). Net reduction of ~50 lines. Adding a new type (e.g.
light-user-data) now requires one line per group instead of a full function per group.What changed
defndynamicgenerators alongside the existingluax--make-push-calls/luax--make-field-stmtshelpersdefmodule Luaxwith generator callsget-carp-str,do-in,call-fn, andmake-tableremain hand-written (they aren't part of the repetitive pattern)What didn't change
Not verified on this machine
The Carp compiler (
carp),carp-fmt, andanglerare not available on the build host. The macro code follows the samedefndynamic+evalpattern used byLua.setupand should work correctly, but compilation has not been verified.Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.