mirror of
https://github.com/wez/wezterm.git
synced 2024-11-22 22:42:48 +03:00
move lua helpers into own crate
This commit is contained in:
parent
52aa9cf71b
commit
d64dab2a2b
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -1783,6 +1783,19 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "luahelper"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bstr 0.2.13",
|
||||||
|
"log",
|
||||||
|
"mlua",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"strsim 0.10.0",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "luajit-src"
|
name = "luajit-src"
|
||||||
version = "210.1.0+resty31116c4"
|
version = "210.1.0+resty31116c4"
|
||||||
@ -4061,6 +4074,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"lru",
|
"lru",
|
||||||
|
"luahelper",
|
||||||
"metrics",
|
"metrics",
|
||||||
"mlua",
|
"mlua",
|
||||||
"notify",
|
"notify",
|
||||||
@ -4082,7 +4096,6 @@ dependencies = [
|
|||||||
"serial",
|
"serial",
|
||||||
"shared_library",
|
"shared_library",
|
||||||
"ssh2",
|
"ssh2",
|
||||||
"strsim 0.10.0",
|
|
||||||
"structopt",
|
"structopt",
|
||||||
"tabout",
|
"tabout",
|
||||||
"terminfo",
|
"terminfo",
|
||||||
|
@ -46,6 +46,7 @@ leb128 = "0.2"
|
|||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
lru = "0.5"
|
lru = "0.5"
|
||||||
|
luahelper = { path = "luahelper" }
|
||||||
open = "1.2"
|
open = "1.2"
|
||||||
pulldown-cmark = "0.7"
|
pulldown-cmark = "0.7"
|
||||||
metrics = { version="0.12", features=["std"]}
|
metrics = { version="0.12", features=["std"]}
|
||||||
@ -66,7 +67,6 @@ serde_json = "1.0"
|
|||||||
serial = "0.4"
|
serial = "0.4"
|
||||||
ssh2 = "0.8"
|
ssh2 = "0.8"
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
strsim = "0.10"
|
|
||||||
tabout = { path = "tabout" }
|
tabout = { path = "tabout" }
|
||||||
wezterm-term = { path = "term", features=["use_serde"] }
|
wezterm-term = { path = "term", features=["use_serde"] }
|
||||||
terminfo = "0.7"
|
terminfo = "0.7"
|
||||||
|
16
luahelper/Cargo.toml
Normal file
16
luahelper/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "luahelper"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Wez Furlong <wez@wezfurlong.org>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bstr = "0.2"
|
||||||
|
log = "0.4"
|
||||||
|
mlua = {version="0.2", features=["vendored"]}
|
||||||
|
serde = {version="1.0", features = ["rc", "derive"]}
|
||||||
|
serde_json = "1.0"
|
||||||
|
strsim = "0.10"
|
||||||
|
thiserror = "1.0"
|
39
luahelper/src/lib.rs
Normal file
39
luahelper/src/lib.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#![macro_use]
|
||||||
|
|
||||||
|
mod serde_lua;
|
||||||
|
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> mlua::ToLua<'lua> for $struct {
|
||||||
|
fn to_lua(self, lua: &'lua mlua::Lua) -> Result<mlua::Value<'lua>, mlua::Error> {
|
||||||
|
Ok(crate::scripting::to_lua_value(lua, self)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'lua> mlua::FromLua<'lua> for $struct {
|
||||||
|
fn from_lua(
|
||||||
|
value: mlua::Value<'lua>,
|
||||||
|
_lua: &'lua mlua::Lua,
|
||||||
|
) -> Result<Self, mlua::Error> {
|
||||||
|
Ok(crate::scripting::from_lua_value(value)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
use luahelper::impl_lua_conversion;
|
||||||
use termwiz::color::RgbColor;
|
use termwiz::color::RgbColor;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::keyassignment::{KeyAssignment, MouseEventTrigger};
|
use crate::keyassignment::{KeyAssignment, MouseEventTrigger};
|
||||||
|
use luahelper::impl_lua_conversion;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use termwiz::input::{KeyCode, Modifiers};
|
use termwiz::input::{KeyCode, Modifiers};
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ use crate::frontend::FrontEndSelection;
|
|||||||
use crate::keyassignment::{KeyAssignment, MouseEventTrigger, SpawnCommand};
|
use crate::keyassignment::{KeyAssignment, MouseEventTrigger, SpawnCommand};
|
||||||
use anyhow::{anyhow, bail, Context, Error};
|
use anyhow::{anyhow, bail, Context, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use luahelper::impl_lua_conversion;
|
||||||
use portable_pty::{CommandBuilder, PtySize};
|
use portable_pty::{CommandBuilder, PtySize};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std;
|
use std;
|
||||||
|
@ -3,6 +3,7 @@ use crate::mux::tab::Tab;
|
|||||||
use crate::mux::window::WindowId;
|
use crate::mux::window::WindowId;
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use downcast_rs::{impl_downcast, Downcast};
|
use downcast_rs::{impl_downcast, Downcast};
|
||||||
|
use luahelper::impl_lua_conversion;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -3,6 +3,7 @@ use crate::config::LeaderKey;
|
|||||||
use crate::frontend::gui::SelectionMode;
|
use crate::frontend::gui::SelectionMode;
|
||||||
use crate::mux::domain::DomainId;
|
use crate::mux::domain::DomainId;
|
||||||
use crate::mux::pane::Pattern;
|
use crate::mux::pane::Pattern;
|
||||||
|
use luahelper::impl_lua_conversion;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -1,42 +1,11 @@
|
|||||||
#![macro_use]
|
|
||||||
|
|
||||||
use crate::config::{FontAttributes, TextStyle};
|
use crate::config::{FontAttributes, TextStyle};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use bstr::BString;
|
use bstr::BString;
|
||||||
|
pub use luahelper::*;
|
||||||
use mlua::{Lua, Table, Value};
|
use mlua::{Lua, Table, Value};
|
||||||
use serde::*;
|
use serde::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
mod serde_lua;
|
|
||||||
|
|
||||||
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_rules! impl_lua_conversion {
|
|
||||||
($struct:ident) => {
|
|
||||||
impl<'lua> mlua::ToLua<'lua> for $struct {
|
|
||||||
fn to_lua(self, lua: &'lua mlua::Lua) -> Result<mlua::Value<'lua>, mlua::Error> {
|
|
||||||
Ok(crate::scripting::to_lua_value(lua, self)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> mlua::FromLua<'lua> for $struct {
|
|
||||||
fn from_lua(
|
|
||||||
value: mlua::Value<'lua>,
|
|
||||||
_lua: &'lua mlua::Lua,
|
|
||||||
) -> Result<Self, mlua::Error> {
|
|
||||||
Ok(crate::scripting::from_lua_value(value)?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set up a lua context for executing some code.
|
/// Set up a lua context for executing some code.
|
||||||
/// The path to the directory containing the configuration is
|
/// The path to the directory containing the configuration is
|
||||||
/// passed in and is used to pre-set some global values in
|
/// passed in and is used to pre-set some global values in
|
||||||
|
Loading…
Reference in New Issue
Block a user