Files
LLeMbas-TTY/luahelper/src/lib.rs
T
Wez Furlong 9d9f3c3c1a lua: add GuiWin and PaneObject proxies for use in script
This commit adds very basic first passes at representing the Pane
and GuiWindow types in lua script.

The `open-uri` event from 9397f2a2db
has been redefined to receive `(window, pane, uri)` parameters
instead of its prior very basic `uri` parameter.

A new key assignment `wezterm.action{EmitEvent="event-name"}` is
now available that allows a key binding assignment to emit an arbitrary
event, which in turn allows for triggering an arbitrary lua callback
in response to a key or mouse click.

`EmitEvent` passes the `(window, pane)` from the triggering window and
pane as parameters.

Here's a brief example:

```lua
local wezterm = require 'wezterm';

wezterm.on("my-thingy", function(window, pane)
  local dims = pane:get_dimensions();
  wezterm.log_error("did my thingy with window " .. window:window_id() ..
    " pane " .. pane:pane_id() .. " " .. dims.cols .. "x" .. dims.viewport_rows);
  window:perform_action("IncreaseFontSize", pane);
end)

return {
  keys = {
     {key="E", mods="CTRL", action=wezterm.action{EmitEvent="my-thingy"}},
  }
}
```

refs: #223
refs: #225
2020-10-09 13:55:36 -07:00

36 lines
1.1 KiB
Rust

#![macro_use]
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(luahelper::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(luahelper::from_lua_value(value)?)
}
}
};
}