From 8d9e00edacbc061ec5efba100e2af71be6824af8 Mon Sep 17 00:00:00 2001 From: Stanisław Zagórowski Date: Thu, 11 Jan 2024 15:29:25 +0100 Subject: luax --- src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f0683ae..466ffbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ fn table_to_html(table: rlua::Table, f: &mut W) -> Result<()> write!(f, "<{}", type_name)?; let mut children = None; + let mut attrs = None; for pair in table.pairs::() { let (key, value) = pair?; if key == "tag" { @@ -28,13 +29,19 @@ fn table_to_html(table: rlua::Table, f: &mut W) -> Result<()> children = Some(value); continue; } - match value { - rlua::Value::Nil => write!(f, " {}=\"\"", key)?, - rlua::Value::Boolean(b) => write!(f, " {}=\"{}\"", key, b)?, - rlua::Value::Integer(i) => write!(f, " {}=\"{}\"", key, i)?, - rlua::Value::Number(n) => write!(f, " {}=\"{}\"", key, n)?, - rlua::Value::String(s) => write!(f, " {}=\"{}\"", key, s.to_str()?)?, - _ => return Err(ReluaxError::LuaX(LuaXError::WrongFieldType(key)).into()), + if key == "attrs" { + attrs = Some(value); + continue; + } + } + if let Some(attrs) = attrs { + if let rlua::Value::Table(attrs) = attrs { + for pair in attrs.pairs::() { + let (key, value) = pair?; + write!(f, " {}=\"{}\"", key, value.to_str()?)?; + } + } else { + return Err(ReluaxError::LuaX(LuaXError::NonTableAttrs).into()); } } write!(f, ">")?; @@ -93,7 +100,8 @@ async fn main() -> color_eyre::Result<()> { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, format!("{} is not a file", entry.display()), - ).into()); + ) + .into()); } server::Server::serve(args.port).await?; -- cgit v1.3.1