pub enum LuaError {
Runtime(LuaValue),
Syntax(LuaValue),
RuntimeMsg(Box<[u8]>),
SyntaxMsg(Box<[u8]>),
Memory,
Error,
Yield,
File,
Gc,
}Expand description
The Lua error type. Carries a LuaValue payload because Lua errors can
be any value (typically a string).
The *Msg variants carry the message as owned bytes instead of a GC
string: host-side code builds errors with no VM (and no active heap) in
scope, and allocating the payload eagerly either required an active
HeapGuard or fell back to a detached, never-freed box (the issue #249
leak class — see #253). The bytes are materialized into a real GC string
by into_value at the moment the error actually
enters a VM, where a heap is active by construction.
Variants§
Runtime(LuaValue)
Syntax(LuaValue)
RuntimeMsg(Box<[u8]>)
SyntaxMsg(Box<[u8]>)
Memory
Error
Yield
File
Gc
Implementations§
Source§impl LuaError
impl LuaError
Sourcepub fn runtime(args: Arguments<'_>) -> LuaError
pub fn runtime(args: Arguments<'_>) -> LuaError
Build a runtime error whose message is owned bytes — no GC
allocation happens here; into_value
materializes the string when the error enters a VM (#253).
pub fn syntax(args: Arguments<'_>) -> LuaError
pub fn syntax_at(args: Arguments<'_>, source: &[u8], line: i32) -> LuaError
pub fn syntax_raw(msg: &[u8]) -> LuaError
pub fn type_error(v: &LuaValue, op: &str) -> LuaError
pub fn call_error(v: &LuaValue) -> LuaError
pub fn concat_error(p1: &LuaValue, p2: &LuaValue) -> LuaError
pub fn arith_error(p1: &LuaValue, p2: &LuaValue, _msg: &str) -> LuaError
pub fn int_overflow(_p1: &LuaValue, _p2: &LuaValue) -> LuaError
pub fn order_error(p1: &LuaValue, p2: &LuaValue) -> LuaError
pub fn for_error(v: &LuaValue, what: &str) -> LuaError
pub fn arg_error(narg: i32, msg: &str) -> LuaError
pub fn type_arg_error(narg: i32, expected: &str, got: &LuaValue) -> LuaError
pub fn from_value(v: LuaValue) -> LuaError
pub fn with_status(status: LuaStatus) -> LuaError
pub fn to_status(&self) -> LuaStatus
Sourcepub fn message_bytes(&self) -> Option<&[u8]>
pub fn message_bytes(&self) -> Option<&[u8]>
The message bytes, when this error carries a textual message —
either a GC string payload or the owned bytes of a not-yet-
materialized *Msg variant. The canonical accessor for host-side
message extraction; callers needing a fallback keep their own.
Never allocates, never panics.
Sourcepub fn into_value(self) -> LuaValue
pub fn into_value(self) -> LuaValue
Convert the error into the Lua value that gets pushed/propagated.
This is the VM-entry boundary for the *Msg variants: the owned
bytes become a real GC string here, via GcRef::new, which requires
an active HeapGuard. Every in-tree call site that pushes an error
object runs inside a guarded region (pcall_k, api::load,
with_state, lua_resume, reset_thread), so the allocation is
always collector-owned — this is what lets the guard-less detached
allocation arm be removed entirely (#253).
§Panics
Panics for RuntimeMsg/SyntaxMsg payloads when no HeapGuard is
active. Host code that only needs the message text should use
message_bytes or
message_lossy instead — those never
allocate and never panic.
Sourcepub fn message_lossy(&self) -> String
pub fn message_lossy(&self) -> String
Human-readable error payload for embedders.
Lua errors can carry any Lua value. When the payload is a byte string,
this returns it using lossy UTF-8 conversion; other payloads fall back to
the Lua type name so host integrations do not have to parse Debug.
Trait Implementations§
Source§impl Error for LuaError
impl Error for LuaError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()