Commit graph

6 commits

Author SHA1 Message Date
Stephen Dennis
8e33b632f9 fix(lua): gate pennies/iswizard/isconnected like softcode (#1287)
Pass D4 residual on the Lua mux.* bridge.

mux.pennies/iswizard/isconnected took raw dbrefs with no Examinable /
pub_flags check, while softcode money() and hasflag() require those
gates. Match the softcode model. Also nil string.dump after opening
the string library (bytecode dump / loader rebuild).

Closes #1287.
2026-07-25 20:05:16 -06:00
Stephen Dennis
691a8aad76 engine/lua: make refcount and JIT cache key atomic (match comsys/mail)
The comsys and mail modules already use std::atomic<uint32_t> for their
COM-style refcounts; the Lua module did not, leaving CLuaMod::m_cRef and
the Lua JIT chunk-cache key counter as plain integers.

- #723: CLuaMod::m_cRef -> std::atomic<uint32_t>, with AddRef/Release using
  fetch_add(relaxed)/fetch_sub(acq_rel) exactly like CComsysMod. (CLuaMod
  has no separate factory class; the registration entry point is a plain
  function, so there is no second counter to convert.)
- #724: jit_lua.cpp s_next_key -> std::atomic<uint64_t> with
  fetch_add(relaxed); the pre-increment value is preserved (first key = 1).

The engine currently runs single-threaded, so neither was exploitable
today; this brings the Lua module in line with the established
correct-by-design refcounting convention so it stays sound if module calls
are ever made off the main thread. No behavioral change; smoke 1064/0.

Closes #723
Closes #724

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 08:40:57 -05:00
Stephen Dennis
2536921959 Close 4 Lua bridge permission holes (ISSUES #1 audit)
mux.notify/pemit: Add @pemit-equivalent permission checks —
nearby, Long_Fingers, Controls, page-lock, pemit_any/pemit_players
config flags. Returns false on denial instead of silently sending.

mux.location: Add locatable() check so UNFINDABLE objects return
nil instead of leaking their location.

mux.name: Add read_rem_name/nearby/control check matching the
name() softcode function. Strip exit aliases (semicolon handling).

mux.controls: Restrict 'who' parameter — executor must be 'who'
or must control 'who', preventing scripts from probing wizard
control relationships.

Also: include externs.h directly (Lua is in engine.so now, not a
separate module) and update stale file-header comment.

551/551 smoke tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 21:28:22 -06:00
Stephen Dennis
c9bea697df Enable generic Lua function calls (math.floor, string.upper, etc.)
The big unlock: GETTABUP now handles ALL _ENV globals (not just "mux"),
and CALL now handles both mux.* bridge calls and general Lua function
calls via __lua_call ECALL. Scripts using math.floor(), string.upper(),
tostring(), or any global function are now JIT-eligible.

Key fix: lua_settop() save/restore in TryJIT around RunCompiled.
ECALL handlers for __lua_getglobal push tables/functions onto the Lua
stack, and __lua_call pushes/pops during lua_pcall. Without cleanup,
the stack overflows on repeated calls. The save/restore ensures every
JIT execution leaves the Lua stack in its original state.

4 new smoke tests (TC043-TC046): math.floor, string.upper, tostring,
math.sqrt — verifying the generic global→field→call path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 16:35:29 -06:00
Stephen Dennis
b5ce590bb2 Thread lua_State through JIT ECALL path for VM callback
Added void *lua_state to eval_ctx, run_cached_program(), and
mux_IJITCompile::RunCompiled(). CLuaMod::TryJIT passes m_L through
the entire chain so ECALL handlers can call back into the Lua VM
for operations the JIT can't handle natively.

nullptr for softcode JIT (no change in behavior). Non-null for
Lua JIT — enables future ECALL handlers for table access, string
ops, generic calls, and upvalue reads.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:19:28 -06:00
Stephen Dennis
22ee824c18 Fold lua_mod into engine.so — Lua is a first-class engine language
Moved lua_mod.cpp/h from mux/modules/lua/ into mux/modules/engine/.
engine.so now links liblua54.a directly (like libsqlite3.a) and
registers CLuaModFactory in its COM front-door.

This eliminates the .so boundary between the Lua VM and the JIT
compiler, enabling future ECALL-back-to-VM for unsupported opcodes
without cross-module callback plumbing.

- Removed standalone module entry points (mux_Register etc.)
- Added lua_mod_create_instance() factory function
- Registered CID_LuaMod in engine_classes[] and mux_GetClassObject
- Removed lua_mod.so build from modules/Makefile.am
- Removed "module lua_mod" from smoke.conf (no longer needed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:11:05 -06:00