| @@ -619,34 +619,56 @@ |
| 619 | 619 | all qualify (an older, lifetime-parameterised mlua would not). This is what makes the |
| 620 | 620 | planned feel-lua (ADR-22) a clean fit rather than a fight with the borrow checker. |
| 621 | 621 | |
| 622 | | -## ADR-22 (planned): Lua bindings (`feel-lua`, mlua) |
| 622 | +## ADR-22: Lua bindings (`feel-lua`, mlua) |
| 623 | 623 | |
| 624 | 624 | - **Context:** feel-core already powers three wrappers (feel-pg, feel-wasm, feel-py). |
| 625 | 625 | Lua is a common embedded-scripting and rules host (game logic, Redis, nginx/ |
| 626 | 626 | OpenResty, Neovim, application plugins), so a fifth target is a natural next step. |
| 627 | | - This entry records the decision and its constraints **before** the crate is built — |
| 628 | | - in the spirit of ADR-5 — so the next increment starts from a decision, not a blank |
| 629 | | - page. *Not yet built.* |
| 630 | | -- **Decision (planned):** a new `crates/feel-lua`, a wrapper over the same core |
| 631 | | - (ADR-1/I1 holds — `mlua` lives only here), built with **mlua ≥ 0.10**. The 0.10 line |
| 632 | | - dropped the `'lua` lifetime parameter, so `Table`/`Value`/`Function` are owned and |
| 633 | | - `'static` and fit the `Arc<dyn ForeignObject + 'static>` seam (ADR-21) directly; an |
| 634 | | - older lifetime-parameterised mlua would not. Like feel-py (PyO3) and feel-pg (pgrx), |
| 635 | | - feel-lua needs a Lua *link context*, so it goes in the workspace `members` but |
| 636 | | - **not** `default-members` (a bare `cargo build` keeps building only the portable |
| 637 | | - members). The three boundary sub-decisions are recorded ahead as **RD-7** (regex), |
| 638 | | - **RD-8** (temporal) and **RD-9** (context mapping); the seven reusable seams are the |
| 639 | | - "Adding a wrapper" contract below. |
| 640 | | -- **Hazard to plan for:** Lua signals errors by `longjmp` (like PostgreSQL — the RD-1 |
| 641 | | - hazard), but mlua already wraps every C-API call and surfaces them as |
| 642 | | - `Result<_, mlua::Error>`. So `LuaForeign::get`/`force` map an `Err` (a raised |
| 643 | | - `__index` metamethod, a bad access) to a value-null — the same defensive pattern |
| 644 | | - feel-py uses around `getattr` (ADR-21). The longjmp never unwinds through Rust |
| 645 | | - frames; mlua catches it at the boundary. |
| 646 | | -- **Consequence (anticipated):** a fifth target on the same core. `Value` stays |
| 647 | | - `!Send` (ADR-21), which *matches* mlua's non-`Send` values rather than fighting them. |
| 648 | | - I2 (ADR-1) relaxes here exactly as it does elsewhere — no Lua regex (RD-7), no native |
| 649 | | - Lua temporal (RD-8) — both loud and documented, neither a surprise. |
| 627 | + This entry was recorded **before** the crate was built (in the spirit of ADR-5) and |
| 628 | + is now realised; the three boundary sub-decisions stand as **RD-7** (regex), |
| 629 | + **RD-8** (temporal) and **RD-9** (context mapping), and the seven reusable seams are |
| 630 | + the "Adding a wrapper" contract below. *Built 2026-06-17.* |
| 631 | +- **Library (reconsidered, not just inherited):** the candidates were re-checked rather |
| 632 | + than taking the original note at face value. **rlua** is deprecated (v0.20 is a thin |
| 633 | + re-export of mlua) — a dead end; **hlua** is effectively unmaintained; **piccolo** (a |
| 634 | + pure-Rust stackless VM) is attractive (no C, sandboxing-focused) but pre-1.0 with an |
| 635 | + incomplete stdlib, *and* its values are `gc-arena`-bound with a `'gc` lifetime — the |
| 636 | + opposite of what the `Arc<dyn ForeignObject + 'static>` seam needs, reintroducing |
| 637 | + exactly the lifetime fight an old lifetime-parameterised mlua would. **mlua** (0.11.6) |
| 638 | + is actively maintained, covers Lua 5.1–5.5 + LuaJIT + Luau, has first-class loadable- |
| 639 | + module support, and — since 0.10 — owned `'static` `Table`/`Function`/`Value`. So mlua |
| 640 | + wins on the merits, not by default. |
| 641 | +- **Decision:** a new `crates/feel-lua`, a wrapper over the same core (ADR-1/I1 holds — |
| 642 | + `mlua` lives only here), built with **mlua 0.11**. It ships as a **Lua-loadable C |
| 643 | + module** (`#[mlua::lua_module] fn feel → luaopen_feel`, exposing |
| 644 | + `feel.evaluate`/`evaluate_strict`/`compile`) — the analogue of feel-py's Python module |
| 645 | + and feel-wasm's JS module. The module-building logic is factored into a plain |
| 646 | + `build_module(&Lua)` so the Rust integration tests drive it against an embedded VM. |
| 647 | + Like feel-py and feel-pg, feel-lua needs a Lua *link context*, so it sits in the |
| 648 | + workspace `members` but **not** `default-members` (a bare `cargo build` keeps building |
| 649 | + only the portable members). Cargo features select the Lua flavour/mode: `default = |
| 650 | + ["lua54", "vendored"]` (the test/embed build, where `Lua::new()` works), with |
| 651 | + `luajit`/`luau` and a `module` feature (link the host's Lua, build the loadable `.so`: |
| 652 | + `cargo build -p feel-lua --no-default-features --features lua54,module`). `vendored` |
| 653 | + and `module` are practically exclusive — one embeds Lua, the other expects the host's. |
| 654 | +- **Hazard handled:** Lua signals errors by `longjmp` (like PostgreSQL — the RD-1 |
| 655 | + hazard), but mlua wraps every C-API call and surfaces them as `Result<_, mlua::Error>`, |
| 656 | + so the longjmp never unwinds through Rust frames. Two distinct mappings: a failed |
| 657 | + **member access** (`LuaForeign::get`/`force`: a raised `__index`, a bad access) is a |
| 658 | + **value-null** (the defensive feel-py `getattr` pattern, ADR-21); a failed **host call** |
| 659 | + (`LuaForeignFn::call`: a raised Lua error) is an **error-null** (`Value::Error`, |
| 660 | + ADR-14/ADR-23), distinct from a callable that simply `return`s `nil` (value-null). |
| 661 | +- **Named arguments:** Lua has no kwargs, so — exactly like feel-wasm's options object — |
| 662 | + FEEL named arguments become a single trailing table `{name = value}`. A returned host |
| 663 | + callable/table passes back **by identity** (`as_any` downcast). Argument marshalling |
| 664 | + uses mlua's `IntoLua` so the conversion runs with the `&Lua` that `Function::call` |
| 665 | + already holds (`ForeignFunction::call` is handed no state). |
| 666 | +- **Consequence:** a fifth target on the same core, verified two ways (per the |
| 667 | + user-chosen "both"): 21 Rust integration tests embedding a vendored VM, and a |
| 668 | + `smoke.lua` run end-to-end through the loadable module under the system `lua5.4`. |
| 669 | + `Value` stays `!Send` (ADR-21), which *matches* mlua's non-`Send` values rather than |
| 670 | + fighting them. I2 (ADR-1) relaxes here exactly as elsewhere — no Lua regex (RD-7), no |
| 671 | + native Lua temporal (RD-8) — both loud and documented, neither a surprise. |
| 650 | 672 | |
| 651 | 673 | ## ADR-23: User-defined functions — FEEL closures and host callables |
| 652 | 674 | |
| @@ -734,7 +756,7 @@ |
| 734 | 756 | |
| 735 | 757 | Per-wrapper choices at a glance (the detail, with revisit triggers, is in RD-1…9): |
| 736 | 758 | |
| 737 | | -| Seam | feel-pg | feel-wasm | feel-py | **feel-lua (planned)** | |
| 759 | +| Seam | feel-pg | feel-wasm | feel-py | **feel-lua** | |
| 738 | 760 | | --- | --- | --- | --- | --- | |
| 739 | 761 | | Input mapping | eager `jsonb` | lazy `JsForeign` | lazy `PyForeign` | lazy `LuaForeign` (RD-9) | |
| 740 | 762 | | Regex dialect | `RustRegex` (RD-1) | `JsRegex` (ADR-16) | `PyRegex`/`re` (RD-4) | `RustRegex` (RD-7) | |
| @@ -900,9 +922,11 @@ |
| 900 | 922 | off the table; the realistic options are (a) keep the bundled `RustRegex` (parity with |
| 901 | 923 | feel-core/TCK, like feel-pg RD-1) or (b) bind a C regex library (`lrexlib`/PCRE) — real |
| 902 | 924 | FFI weight for a marginal gain. |
| 903 | | -- **Decision (planned):** feel-lua keeps the default `RustRegex` provider — same dialect |
| 904 | | - as feel-core and the TCK fixtures (the validated reference), and no native dependency. |
| 905 | | - The `evaluate_with_env` seam leaves the door open. |
| 925 | +- **Decision (2026-06-17, implemented):** feel-lua keeps the default `RustRegex` provider |
| 926 | + — same dialect as feel-core and the TCK fixtures (the validated reference), and no native |
| 927 | + dependency. Because the feel-core dependency keeps its default features, no regex feature |
| 928 | + flag is needed here (simpler than feel-wasm/feel-py). The `evaluate_with_env` seam leaves |
| 929 | + the door open. |
| 906 | 930 | - **Revisit trigger:** a concrete need for FEEL regex in Lua to match a host PCRE binding |
| 907 | 931 | users already author against. |
| 908 | 932 | - **If flipped:** implement `struct LuaRegex` over `lrexlib`/PCRE as a |
| @@ -916,10 +940,12 @@ |
| 916 | 940 | `{year=, month=, …}` tables). Options for the five FEEL temporal types: ISO-8601 strings |
| 917 | 941 | (as feel-wasm leaves durations), `os.date`-style tables, or userdata from a Lua datetime |
| 918 | 942 | library. |
| 919 | | -- **Decision (planned):** map every temporal type to/from a **canonical ISO-8601 string** — |
| 920 | | - the portable boundary ADR-18 already produces, with zero extra dependency and no lossy |
| 921 | | - conversion. A convenience `os.date`-style table form (`{year=, month=, day=, …}`) on input |
| 922 | | - is a possible later addition, not the default. |
| 943 | +- **Decision (2026-06-17, implemented):** map every temporal **result** to a **canonical |
| 944 | + ISO-8601 string** (via `temporal::to_iso`) — the portable boundary ADR-18 already |
| 945 | + produces, with zero extra dependency and no lossy conversion. On input there is no native |
| 946 | + Lua temporal type, so a date/time is just a string the FEEL `date()`/`time()`/`duration()` |
| 947 | + builtins parse. A convenience `os.date`-style table form (`{year=, month=, day=, …}`) on |
| 948 | + input is a possible later addition, not the default. |
| 923 | 949 | - **Revisit trigger:** users want first-class Lua date objects (integration with a specific |
| 924 | 950 | Lua datetime lib) rather than ISO strings. |
| 925 | 951 | - **If flipped:** add a table/userdata mapping in the wrapper boundary (`to_iso`/ |
| @@ -931,11 +957,16 @@ |
| 931 | 957 | deep table resolves one dot at a time. A Lua table can carry an `__index` metamethod (a |
| 932 | 958 | computed/lazy field) exactly like a Python `@property`, so the lazy seam fits; an eager |
| 933 | 959 | alternative would snapshot and miss metamethod semantics. |
| 934 | | -- **Decision (planned):** wrap an `mlua::Table` (or userdata) in a `LuaForeign` implementing |
| 935 | | - `ForeignObject`: `get` via `Table::get` (which fires `__index`, the on-demand load), an |
| 936 | | - `Err` → value-null; `force` enumerates the table's own pairs one level; `as_any` recovers |
| 937 | | - the handle for identity pass-through. Scalars and temporals (RD-8) stay eager. Mirrors |
| 938 | | - feel-py's `PyForeign` and feel-wasm's `JsForeign`. |
| 960 | +- **Decision (2026-06-17, implemented):** wrap an `mlua::Table` in a `LuaForeign` |
| 961 | + implementing `ForeignObject`: `get` via `Table::get` (which fires `__index`, the |
| 962 | + on-demand load), an `Err` → value-null; `force` materialises one level — a sequence |
| 963 | + (`#t >= 1`) becomes a `Value::List` of `t[1..=#t]`, any other table a `Value::Context` of |
| 964 | + its string-keyed pairs; `as_any` recovers the handle for identity pass-through. Scalars |
| 965 | + and temporals (RD-8) stay eager. Mirrors feel-py's `PyForeign` and feel-wasm's |
| 966 | + `JsForeign`. **Documented simplification:** a Lua table is ambiguous (it is both array |
| 967 | + and map), so the sequence/map split is a heuristic — a *mixed* table's hash part is |
| 968 | + dropped when a sequence border exists, non-string map keys are dropped, and an empty |
| 969 | + table forces to an empty context (not an empty list). |
| 939 | 970 | - **Revisit trigger:** a need to forbid metamethod side effects entirely during evaluation |
| 940 | 971 | (a hard "no `__index` runs" guarantee). |
| 941 | 972 | - **If flipped:** offer an opt-in eager snapshot (force the whole subtree at the boundary) |