Skip to content

Optional lua-rs backend: run scripts on a pure-Rust Lua VM (behind a feature flag)#89

Open
ianm199 wants to merge 1 commit into
kpcyrd:mainfrom
ianm199:lua-rs-port-spike
Open

Optional lua-rs backend: run scripts on a pure-Rust Lua VM (behind a feature flag)#89
ianm199 wants to merge 1 commit into
kpcyrd:mainfrom
ianm199:lua-rs-port-spike

Conversation

@ianm199

@ianm199 ianm199 commented May 25, 2026

Copy link
Copy Markdown

Draft / experimental — following up on the Reddit thread where you mentioned authoscope and sn0int. This wires authoscope's Lua scripting onto a pure-Rust Lua 5.4 VM behind an opt-in flag, so it's easy to try without touching the default build.

  • What: new lua-rs feature that swaps the C-FFI hlua-badtouch bindings for lua-rs-hlua-shim, an hlua-0.4-compatible API backed by the lua-rs VM. default = ["hlua-badtouch"] — the normal build is unchanged.
  • The diff is tiny: one #[cfg]'d import in src/lib.rs plus the optional dep. runtime.rs, the 47 host functions, and every .lua script are untouched.
  • Why bother: it removes the C interpreter and the unsafe FFI boundary for the scripting layer — the lua-rs VM is #![forbid(unsafe_code)], so the class of "weird memory issues across the FFI" you mentioned is gone for that part.
  • Verified: all 24 lib tests pass on lua-rs, and authoscope run gives byte-identical stdout + exit codes vs the C-hlua build for hmac/hex/base64/json and live httpbin basic-auth, on both valid and invalid creds. Try it: cargo build --no-default-features --features lua-rs.
  • Known gaps (it's a spike): the shim opens the full stdlib rather than string-only, so it widens the sandbox vs the C build — would tighten that before this is more than a demo. Lua 5.2→5.4 jump surfaced no issues with these scripts. Genuinely curious whether it holds up on your real modules.

Adds a `lua-rs` feature that swaps the C-FFI `hlua-badtouch` bindings for
`lua-rs-hlua-shim`, an hlua-compatible API backed by the pure-Rust lua-rs
Lua 5.4 VM. Default build is unchanged (`default = ["hlua-badtouch"]`); the
swap is a single cfg'd import in src/lib.rs.

Build/run on lua-rs with:
    cargo build --no-default-features --features lua-rs

Verified: all 24 lib tests pass on lua-rs, and `authoscope run` produces
byte-identical output and exit codes vs the C-hlua build for compute
(hmac/hex/base64/json) and live HTTP basic-auth, valid and invalid creds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ianm199 ianm199 force-pushed the lua-rs-port-spike branch from 2c8f139 to 50f228a Compare May 25, 2026 17:59
@ianm199 ianm199 marked this pull request as ready for review May 25, 2026 18:10
@ianm199

ianm199 commented May 25, 2026

Copy link
Copy Markdown
Author

@kpcyrd Made the change here and it seems to pass your tests still! Going to spend some more time looking into it

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