aboutsummaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lua.rs b/src/lua.rs
index d9f1511..5dced2d 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -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)?;