Skip to content

feat: Add Lua backend (community contribution welcome) #10

Description

@Goldziher

Goal

Add a Lua binding generator backend for alef, alongside the existing 16 backends (Python/Node/Ruby/PHP/Elixir/Go/Java/C#/WASM/R/Kotlin/Gleam/Zig/Dart/Swift + the C-FFI base).

Approach

Lua is a C FFI consumer (analogous to Go, Java, C#, Zig in the existing codebase). It reuses the cbindgen-produced shared library and consumes the C ABI via Lua's ffi (LuaJIT) or mlua/lua-ffi-rs for standard Lua 5.4.

Reference implementation

The Zig backend is the closest template:

  • crates/alef-backend-zig/src/{lib.rs, gen_bindings.rs, type_map.rs}
  • Reuses alef-codegen::c_consumer::{free_string_symbol, last_error_code_symbol, last_error_context_symbol}
  • Scaffold: crates/alef-scaffold/src/languages/zig.rs
  • E2E: crates/alef-e2e/src/codegen/zig.rs
  • Publish: crates/alef-publish/src/package/zig.rs

Suggested scope (stage discipline)

  1. Stage A: New crate crates/alef-backend-lua/ skeleton (Cargo.toml, lib.rs, gen_bindings.rs returning Ok(vec![]), type_map.rs with LuaMapper: TypeMapper impl). Wire into crates/alef-cli/src/registry.rs and crates/alef-core/src/config/extras.rs::Language.
  2. Stage B: struct/enum/function emission. Lua tables as DTOs; metatables for OOP-style enums; error() for Result error propagation.
  3. Stage C: error wrapping (Lua pcall pattern), async via coroutines.
  4. Stage 1b: scaffold (rockspec), e2e (busted), publish (LuaRocks tarball). Add LUA_KEYWORDS to crates/alef-core/src/keywords.rs (mirroring the cross-cutting follow-up fix(codegen): prefix unused Map key with underscore #7 pattern in the plan).

Pin versions

Add to crates/alef-core/src/template_versions.rs::luarocks (new submodule) — list of test/lint dep versions with Renovate markers (// renovate: datasource=...).

Effort estimate

S–M (~3–5 days for one engineer; similar to Zig).

Tracking

Part of Tier 2 (community-contribution) per the language-backend expansion plan. Other Tier 2 langs being filed: OCaml, Nim, Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions