Lua.VM.Display (Lua v1.0.0-rc.1)

View Source

Boundary wrappers that turn opaque VM value tags into display structs at the Lua.eval!/2 return path.

The internal VM continues to use the tagged-tuple representation ({:tref, id}, {:lua_closure, proto, upvalues}, {:native_func, fun}, {:udref, id}). These wrappers exist purely so that values that surface to user code in iex render legibly instead of as opaque tuples.

See Lua.VM.Display.Table, Lua.VM.Display.Closure, Lua.VM.Display.NativeFunc, and Lua.VM.Display.Userdata for the per-tag display structs and their Inspect impls.

Decode behaviour

Tagdecode: truedecode: false
{:tref, _}list of {k, v} (unchanged)wraps to Display.Table
{:udref, _}{:userdata, term} (unchanged)wraps to Display.Userdata
{:lua_closure, _, _}wraps to Display.Closurewraps to Display.Closure
{:native_func, _}wraps to Display.NativeFuncwraps to Display.NativeFunc

Default-decode tables and userdata are left in their existing Elixir-friendly shape so deflua flows and downstream consumers do not need to change.

Summary

Types

Any of the four display structs produced at the eval boundary.

Functions

Returns true when the value is one of the four display structs.

Unwraps a display struct back to its underlying VM tag tuple.

Wraps each value in a list of eval results for display, given the state at boundary-cross time and the decode: option.

Wraps a single eval-result value for display.

Types

display_struct()

Any of the four display structs produced at the eval boundary.

Functions

display_struct?(arg1)

@spec display_struct?(term()) :: boolean()

Returns true when the value is one of the four display structs.

Used by API entry points (Lua.set!/3, Lua.encode!/2, etc.) to detect a wrapped-for-display value that should be unwrapped back to its underlying VM tag before further processing.

unwrap(other)

@spec unwrap(term()) :: term()

Unwraps a display struct back to its underlying VM tag tuple.

Returns the value unchanged if it is not a display struct.

wrap_results(values, state, decode?)

@spec wrap_results([term()], Lua.VM.State.t(), boolean()) :: [term()]

Wraps each value in a list of eval results for display, given the state at boundary-cross time and the decode: option.

When decode: true (the default), tables and userdata are passed through unchanged because they have already been decoded into Elixir-friendly shapes (list of tuples and {:userdata, term}). Closures and native funcs are wrapped in either mode.

When decode: false, all four tag kinds are wrapped; nested values inside tables are also wrapped via wrap_value/2.

wrap_value(value, state, decode?)

@spec wrap_value(term(), Lua.VM.State.t(), boolean()) :: term()

Wraps a single eval-result value for display.

See wrap_results/3 for the decode-mode matrix.