mod fs;
mod io;
mod template;
mod txt;
use anyhow::Result;
use mlua::{Function, IntoLua, Lua, LuaSerdeExt, Table, Value};
pub type WefterModuleTable<'a> = Vec<(&'a str, Function)>;
pub const LUA_WEFTER_TABLE_NAME: &str = "wefter";
pub const LUA_WEFTER_VERSION: (&str, &str) = ("WEFTER_VERSION", env!("CARGO_PKG_VERSION"));
pub const LUA_WEFTER_PROJECT_ROOT: &str = "WEFTER_PROJECT_ROOT";
pub use fs::module as fs_module;
pub use io::module as io_module;
pub use template::module as template_module;
pub use txt::module as txt_module;
fn wrap_error_tuple<T: IntoLua, E: ToString>(
lua: &Lua,
res: Result<T, E>,
) -> Result<(Value, Value), mlua::Error> {
Ok(match res {
Result::Ok(value) => (value.into_lua(lua)?, Value::Nil),
Result::Err(err) => (Value::Nil, err.to_string().into_lua(lua)?),
})
}
pub fn serialize_table(lua: &Lua, table: Table) -> Result<serde_json::Value> {
let value: Value = Value::Table(table);
let json: serde_json::Value = lua.from_value(value)?;
Ok(json)
}