pub struct LuaError(pub Value);Expand description
A Lua error: an arbitrary Lua value (almost always a string) plus
classification metadata recorded on the Vm side.
LuaError itself is Copy (16 bytes) — embedders matching on the
error value do so via e.0. Richer error context (kind, source,
traceback) lives on the Vm and is accessed through:
Vm::error_text— formatted messageVm::error_kind—LuaErrorKindclassificationVm::error_source—(source_name, line)of the most recent errorVm::take_error_traceback— formatted traceback
use luna_core::vm::{Vm, LuaError, LuaErrorKind};
use luna_core::version::LuaVersion;
let mut vm = Vm::sandbox(LuaVersion::Lua55).open_base().build();
let err: LuaError = vm.eval("syntax error here").unwrap_err();
// The error value is a string (PUC convention):
assert!(err.0.try_as_str().is_some());
// Vm-side metadata records the classification:
assert_eq!(vm.error_kind(), LuaErrorKind::Syntax);Tuple Fields§
§0: ValueImplementations§
Trait Implementations§
impl Copy for LuaError
Source§impl Error for LuaError
impl Error for LuaError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Lua errors do not carry a chained Rust-side source — the
causal chain (__index failure → metamethod error → top-level
failure) is captured in the traceback accessible via
Vm::take_error_traceback.
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<TableError> for LuaError
impl From<TableError> for LuaError
Source§fn from(_: TableError) -> LuaError
fn from(_: TableError) -> LuaError
Lift a TableError into a LuaError carrying Value::Nil.
Heap-free so it composes with ? in functions that don’t have
a &mut Vm. The classification is later refined when the error
crosses a Vm boundary (caller can set
Vm::set_error_kind if needed).