diff --git a/Cargo.lock b/Cargo.lock index ec6d475fd..87ff5d3fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2021,7 +2021,6 @@ dependencies = [ "bstr 0.2.17", "log", "mlua", - "strsim 0.10.0", "wezterm-dynamic", ] @@ -2229,9 +2228,8 @@ dependencies = [ [[package]] name = "mlua" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e2194305aa8301d5da9c1c98640047f4219f6b95c190f6860338ab9872b686" +version = "0.8.0-beta.4" +source = "git+https://github.com/wez/mlua?branch=table_to_pointer#7884481691169044c18a77ec495886db0d02bee9" dependencies = [ "bstr 0.2.17", "cc", diff --git a/Cargo.toml b/Cargo.toml index 65ba24391..ba1de30e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ split-debuginfo = "unpacked" [patch.crates-io] xcb = {version="1.1", git="https://github.com/wez/rust-xcb", branch="ffi"} +mlua = {version="0.8.0-beta.4", git="https://github.com/wez/mlua", branch="table_to_pointer"} diff --git a/config/Cargo.toml b/config/Cargo.toml index 4ad5898db..ce80327c7 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -25,7 +25,7 @@ lazy_static = "1.4" libc = "0.2" log = "0.4" luahelper = { path = "../luahelper" } -mlua = {version="0.7", features=["vendored", "lua54", "async", "send"]} +mlua = {version="0.8.0-beta.4", features=["vendored", "lua54", "async", "send"]} # file change notification notify = "4.0" open = "2.0" diff --git a/config/src/config.rs b/config/src/config.rs index d6114c6c1..79b719091 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -705,7 +705,7 @@ impl Config { // file. Note that we can't catch this happening for files that are // imported via the lua require function. lua.load(s.trim_start_matches('\u{FEFF}')) - .set_name(p.to_string_lossy().as_bytes())? + .set_name(p.to_string_lossy())? .eval_async(), )?; let config = Self::apply_overrides_to(&lua, config)?; diff --git a/luahelper/Cargo.toml b/luahelper/Cargo.toml index 46e966131..3574367c0 100644 --- a/luahelper/Cargo.toml +++ b/luahelper/Cargo.toml @@ -9,6 +9,5 @@ edition = "2018" [dependencies] bstr = "0.2" log = "0.4" -mlua = "0.7" -strsim = "0.10" +mlua = "0.8.0-beta.4" wezterm-dynamic = { path = "../wezterm-dynamic" } diff --git a/luahelper/src/lib.rs b/luahelper/src/lib.rs index ba3faf621..556b6bea1 100644 --- a/luahelper/src/lib.rs +++ b/luahelper/src/lib.rs @@ -2,7 +2,7 @@ pub use mlua; use mlua::{ToLua, Value as LuaValue}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashSet}; use wezterm_dynamic::{FromDynamic, ToDynamic, Value as DynValue}; /// Implement lua conversion traits for a type. @@ -76,8 +76,15 @@ pub fn dynamic_to_lua_value<'lua>( }) } -/// FIXME: lua_value_to_dynamic should detect and avoid cycles in the underlying lua object pub fn lua_value_to_dynamic(value: LuaValue) -> mlua::Result { + let mut visited = HashSet::new(); + lua_value_to_dynamic_impl(value, &mut visited) +} + +fn lua_value_to_dynamic_impl( + value: LuaValue, + visited: &mut HashSet, +) -> mlua::Result { Ok(match value { LuaValue::Nil => DynValue::Null, LuaValue::String(s) => DynValue::String(s.to_str()?.to_string()), @@ -107,6 +114,14 @@ pub fn lua_value_to_dynamic(value: LuaValue) -> mlua::Result { } LuaValue::Error(e) => return Err(e), LuaValue::Table(table) => { + let ptr = table.to_pointer() as usize; + if visited.contains(&ptr) { + // Skip this one, as we've seen it before. + // Treat it as a Null value. + return Ok(DynValue::Null); + } + visited.insert(ptr); + if let Ok(true) = table.contains_key(1) { let mut array = vec![]; for value in table.sequence_values() { diff --git a/mux/Cargo.toml b/mux/Cargo.toml index bcbe1d527..d7d149f7a 100644 --- a/mux/Cargo.toml +++ b/mux/Cargo.toml @@ -22,7 +22,7 @@ libc = "0.2" log = "0.4" luahelper = { path = "../luahelper" } metrics = { version="0.17", features=["std"]} -mlua = "0.7" +mlua = "0.8.0-beta.4" names = { version = "0.12", default-features = false } percent-encoding = "2" portable-pty = { path = "../pty", features = ["serde_support"]} diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index 426d5cff5..cb73f4c9f 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -42,7 +42,7 @@ log = "0.4" lru = "0.7" luahelper = { path = "../luahelper" } metrics = { version="0.17", features=["std"]} -mlua = "0.7" +mlua = "0.8.0-beta.4" mux = { path = "../mux" } open = "2.0" ordered-float = "3.0"