Files
LLeMbas-TTY/luahelper/src/lib.rs
T
Wez Furlong 09f0421b48 add lua repl to the debug overlay
`wezterm` is pre-imported.
The repl prints the result of the expressions to the overlay.

refs: https://github.com/wez/wezterm/issues/641
2021-05-03 09:19:44 -07:00

45 lines
1.3 KiB
Rust

#![macro_use]
use serde::{Deserialize, Serialize};
mod serde_lua;
pub use mlua;
pub use serde_lua::from_lua_value;
pub use serde_lua::ser::to_lua_value;
/// Implement lua conversion traits for a type.
/// This implementation requires that the type implement
/// serde Serialize and Deserialize.
/// Why do we need these traits? They allow `create_function` to
/// operate in terms of our internal types rather than forcing
/// the implementer to use generic Value parameter or return values.
#[macro_export]
macro_rules! impl_lua_conversion {
($struct:ident) => {
impl<'lua> $crate::mlua::ToLua<'lua> for $struct {
fn to_lua(
self,
lua: &'lua $crate::mlua::Lua,
) -> Result<$crate::mlua::Value<'lua>, $crate::mlua::Error> {
Ok($crate::to_lua_value(lua, self)?)
}
}
impl<'lua> $crate::mlua::FromLua<'lua> for $struct {
fn from_lua(
value: $crate::mlua::Value<'lua>,
_lua: &'lua $crate::mlua::Lua,
) -> Result<Self, $crate::mlua::Error> {
Ok($crate::from_lua_value(value)?)
}
}
};
}
pub use serde_lua::ValueWrapper;
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub struct JsonLua(pub serde_json::Value);
impl_lua_conversion!(JsonLua);