Skip to main content

lje.vm

LuaJIT virtual machine manipulation, including bytecode patching and engine call interception.

Functions

lje.vm.patch_bytecodes()

Note: You do not need to ever call this. LJE automatically calls it at preinit.

Patches several LuaJIT bytecode handlers for this VM state to LJE-aware versions. Specifically:

  • ISEQV / ISNEV — patched to use spoof-aware equality comparisons, since the default fast-path breaks for spoofed functions.
  • TGETS — patched to block or remap metatable lookups when LJE remaps are active.
  • CALLT / CALLMT — patched to support tail-call interception.

Also flushes all JIT traces before patching. Should be called once during initialization.

lje.vm.set_engine_call_hook(fn)

Note: Any engine call hook that handles the call first will suppress it from reaching any other engine call hook.

Registers a Lua function to be called when the engine invokes a hooked function. The callback is automatically marked as special and stored per-script. Requires an active script context. Only one hook can be active per script at a time.

Parameters

NameTypeDescription
fnfunction

Must be a Lua function, not a C function.

Errors

  • No active script context.
  • Argument 1 must be a Lua function (not a C function).

lje.vm.handle_engine_call()

Marks the current engine call as handled. Call this from within an engine call hook to signal that LJE should not perform its default handling for this call.

After calling this function, return any values that should be returned to the engine. If you don't, the engine may get confused and explode.

lje.vm.handle_engine_call()
return value1, value2, ...