diff options
Diffstat (limited to 'src/lua.rs')
-rw-r--r-- | src/lua.rs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -1,15 +1,20 @@ use std::fmt::Display; +use std::ops::Index; use std::path::Path; use std::str::from_utf8; +use std::sync::Arc; use rlua::Function; use rlua::HookTriggers; use rlua::Lua; +use rlua::MetaMethod; use rlua::StdLib; use rlua::Table; use crate::Context; +mod serde; + pub struct Script<'a> { pub lua_module_name: &'a str, input: &'a str, @@ -80,6 +85,23 @@ impl<'a> Script<'a> { ) .unwrap(); + ctx.globals() + .get::<_, Table>("gitpad") + .unwrap() + .set( + "decode_toml", + ctx.create_function(|_ctx, text: String| { + toml::from_str::<toml::Value>(&text) + .map_err(|e| rlua::Error::ExternalError(Arc::new(e))) + .and_then(|v| { + serde::to_value(_ctx, v) + .map_err(|e| rlua::Error::ExternalError(Arc::new(e))) + }) + }) + .map_err(ScriptError::LuaError)?, + ) + .unwrap(); + let module: Table = ctx.load(lua_code).eval().map_err(ScriptError::LuaError)?; let view: Function = module.get("view").map_err(ScriptError::LuaError)?; |