#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LuaError {
RuntimeError,
CompileError,
Yield,
StackOverflow,
OutOfMemory,
IndexOutOfBounds,
Exit,
CloseThread,
ErrorInErrorHandling,
}
impl std::fmt::Display for LuaError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LuaError::RuntimeError => write!(f, "Runtime Error"),
LuaError::CompileError => write!(f, "Compile Error"),
LuaError::Yield => write!(f, "Coroutine Yield"),
LuaError::StackOverflow => write!(f, "Stack Overflow"),
LuaError::IndexOutOfBounds => write!(f, "Index Out Of Bounds"),
LuaError::OutOfMemory => write!(f, "Out Of Memory"),
LuaError::Exit => write!(f, "VM Exit"),
LuaError::CloseThread => write!(f, "Close Thread"),
LuaError::ErrorInErrorHandling => write!(f, "Error In Error Handling"),
}
}
}
impl std::error::Error for LuaError {}
#[derive(Debug, Clone)]
pub struct LuaFullError {
pub kind: LuaError,
pub message: String,
}
impl std::fmt::Display for LuaFullError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.message.is_empty() {
write!(f, "{}", self.kind)
} else {
write!(f, "{}", self.message)
}
}
}
impl std::error::Error for LuaFullError {}
impl LuaFullError {
#[inline]
pub fn kind(&self) -> LuaError {
self.kind
}
#[inline]
pub fn message(&self) -> &str {
&self.message
}
}