aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua.rs42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/lua.rs b/src/lua.rs
index e9c4841..d8d82b2 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -44,30 +44,24 @@ pub fn lua_context<A>(run: impl FnOnce(rlua::Context) -> rlua::Result<A>) -> rlu
);
lua.context(|ctx| {
- ctx.globals()
- .raw_set(
- "gitpad",
- ctx.load(include_str!("static/api.lua"))
- .eval::<Table>()
- .expect("error in api.lua"),
- )
- .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)))
- })
- })?,
- )
- .unwrap();
+ let api: Table = ctx
+ .load(include_str!("static/api.lua"))
+ .eval::<Table>()
+ .expect("error in api.lua");
+
+ api.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)))
+ })
+ })?,
+ )?;
+
+ ctx.globals().raw_set("gitpad", api).unwrap();
run(ctx)
})