feat!: display newlines properly

This commit is contained in:
2025-03-18 17:24:59 -04:00
parent e3cdf4260e
commit 417a234cd2
4 changed files with 73 additions and 44 deletions

View File

@@ -15,10 +15,12 @@ pub mod matrix;
use crate::{ListenerMap, build_info::built};
use mlua::{Lua, Table};
use std::io;
use std::{
fmt::{self, Display, Formatter},
io,
};
#[derive(Debug)]
#[allow(dead_code)]
pub enum Error {
CreateEnv(mlua::Error),
EvalChunk(mlua::Error),
@@ -28,6 +30,23 @@ pub enum Error {
ReadFile(io::Error),
}
impl Display for Error {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(
formatter,
"failed to {}",
match self {
Error::CreateEnv(error) => format!("create environment: {error}"),
Error::EvalChunk(error) => format!("evaluate chunk: {error}"),
Error::ExecChunk(error) => format!("execute chunk: {error}"),
Error::LoadChunk(error) => format!("load chunk: {error}"),
Error::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
Error::ReadFile(error) => format!("read script file: {error}"),
}
)
}
}
pub fn register_globals(
lua: &Lua,
globals: &Table,