From 25b5497ffdce29bf825060881a28176b3d4b408e Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Thu, 16 Jan 2025 23:41:47 +0100 Subject: [PATCH] #1395 Fix build errors caused by new mlua --- Cargo.lock | 1 + Cargo.toml | 2 +- main/src/application/unit_model.rs | 5 +--- .../src/domain/flexible_midi_source_script.rs | 2 +- main/src/domain/lua_feedback_script.rs | 28 +++++++++---------- main/src/domain/lua_midi_source_script.rs | 14 +++++----- main/src/domain/lua_module_container.rs | 8 +++--- main/src/domain/lua_support.rs | 16 +++++------ main/src/domain/main_processor.rs | 4 +-- main/src/domain/midi_source.rs | 2 +- main/src/domain/mode.rs | 4 +-- main/src/domain/source.rs | 2 +- main/src/infrastructure/ui/import.rs | 2 +- 13 files changed, 44 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d2181bda3..efe709f88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4316,6 +4316,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea43c3ffac2d0798bd7128815212dd78c98316b299b7a902dabef13dc7b6b8d" dependencies = [ + "anyhow", "bstr 1.9.0", "either", "erased-serde", diff --git a/Cargo.toml b/Cargo.toml index b48b84e7d..b149df6e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ num_enum = "0.7.2" nom = "7.0.0" semver = { version = "1.0.17", features = ["serde"] } enumset = "1.0.12" -mlua = { version = "0.10.2", features = ["vendored", "luau", "serialize"] } +mlua = { version = "0.10.2", features = ["vendored", "luau", "serialize", "anyhow"] } chrono = "0.4.11" dirs = "5.0.1" libloading = "0.8" diff --git a/main/src/application/unit_model.rs b/main/src/application/unit_model.rs index a1f8d17e6..b85f8b1c5 100644 --- a/main/src/application/unit_model.rs +++ b/main/src/application/unit_model.rs @@ -3097,10 +3097,7 @@ impl RealearnControlSurfaceMainTaskSender { const SESSION_GONE: &str = "session gone"; -fn compile_common_lua( - compartment: CompartmentKind, - code: &str, -) -> anyhow::Result> { +fn compile_common_lua(compartment: CompartmentKind, code: &str) -> anyhow::Result { let lua = unsafe { Backbone::main_thread_lua() }; let env = lua.create_fresh_environment(false)?; let require = lua.as_ref().create_function(move |lua, path: String| { diff --git a/main/src/domain/flexible_midi_source_script.rs b/main/src/domain/flexible_midi_source_script.rs index c4a22d41f..71290695c 100644 --- a/main/src/domain/flexible_midi_source_script.rs +++ b/main/src/domain/flexible_midi_source_script.rs @@ -9,7 +9,7 @@ pub enum FlexibleMidiSourceScript<'lua> { } impl<'a, 'lua: 'a> MidiSourceScript<'a> for FlexibleMidiSourceScript<'lua> { - type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a, 'lua>; + type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a>; fn execute( &self, diff --git a/main/src/domain/lua_feedback_script.rs b/main/src/domain/lua_feedback_script.rs index e1ff60169..ad5bd42cd 100644 --- a/main/src/domain/lua_feedback_script.rs +++ b/main/src/domain/lua_feedback_script.rs @@ -11,22 +11,22 @@ use std::cell::RefCell; use std::error::Error; #[derive(Copy, Clone, Debug, Default)] -pub struct AdditionalLuaFeedbackScriptInput<'a, 'lua> { - pub compartment_lua: Option<&'a mlua::Value<'lua>>, +pub struct AdditionalLuaFeedbackScriptInput<'a> { + pub compartment_lua: Option<&'a mlua::Value>, } #[derive(Debug)] -pub struct LuaFeedbackScript<'lua> { - lua: &'lua SafeLua, - function: Function<'lua>, - env: Table<'lua>, - context_key: Value<'lua>, +pub struct LuaFeedbackScript<'a> { + lua: &'a SafeLua, + function: Function, + env: Table, + context_key: Value, } unsafe impl<'a> Send for LuaFeedbackScript<'a> {} -impl<'lua> LuaFeedbackScript<'lua> { - pub fn compile(lua: &'lua SafeLua, lua_script: &str) -> anyhow::Result { +impl<'a> LuaFeedbackScript<'a> { + pub fn compile(lua: &'a SafeLua, lua_script: &str) -> anyhow::Result { ensure!(!lua_script.trim().is_empty(), "script empty"); let env = lua.create_fresh_environment(false)?; let function = lua.compile_as_function("Feedback script", lua_script, env.clone())?; @@ -42,7 +42,7 @@ impl<'lua> LuaFeedbackScript<'lua> { fn feedback_internal( &self, input: FeedbackScriptInput, - additional_input: as FeedbackScript>::AdditionalInput, + additional_input: as FeedbackScript<'a>>::AdditionalInput, ) -> anyhow::Result { let lua = self.lua.as_ref(); let value = lua.scope(|scope| { @@ -97,8 +97,8 @@ pub fn create_lua_feedback_script_runtime(_lua: &Lua) -> mlua::Value { struct LuaPropValue(PropValue); -impl<'lua> IntoLua<'lua> for LuaPropValue { - fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { +impl IntoLua for LuaPropValue { + fn into_lua(self, lua: &Lua) -> mlua::Result { match self.0 { PropValue::Normalized(p) => p.get().into_lua(lua), PropValue::Index(i) => i.into_lua(lua), @@ -115,8 +115,8 @@ impl<'lua> IntoLua<'lua> for LuaPropValue { } } -impl<'a, 'lua: 'a> FeedbackScript<'a> for LuaFeedbackScript<'lua> { - type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a, 'lua>; +impl<'a> FeedbackScript<'a> for LuaFeedbackScript<'a> { + type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a>; fn feedback( &self, diff --git a/main/src/domain/lua_midi_source_script.rs b/main/src/domain/lua_midi_source_script.rs index 37f5c83b6..cadd514a9 100644 --- a/main/src/domain/lua_midi_source_script.rs +++ b/main/src/domain/lua_midi_source_script.rs @@ -8,17 +8,17 @@ use mlua::{Function, IntoLua, Lua, LuaSerdeExt, Table, Value}; use std::borrow::Cow; #[derive(Copy, Clone, Debug, Default)] -pub struct AdditionalLuaMidiSourceScriptInput<'a, 'lua> { - pub compartment_lua: Option<&'a mlua::Value<'lua>>, +pub struct AdditionalLuaMidiSourceScriptInput<'a> { + pub compartment_lua: Option<&'a mlua::Value>, } #[derive(Debug)] pub struct LuaMidiSourceScript<'lua> { lua: &'lua SafeLua, - function: Function<'lua>, - env: Table<'lua>, - y_key: Value<'lua>, - context_key: Value<'lua>, + function: Function, + env: Table, + y_key: Value, + context_key: Value, } unsafe impl<'a> Send for LuaMidiSourceScript<'a> {} @@ -46,7 +46,7 @@ struct ScriptContext { } impl<'a, 'lua: 'a> MidiSourceScript<'a> for LuaMidiSourceScript<'lua> { - type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a, 'lua>; + type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a>; fn execute( &self, diff --git a/main/src/domain/lua_module_container.rs b/main/src/domain/lua_module_container.rs index 9be54a0d9..82fa39c69 100644 --- a/main/src/domain/lua_module_container.rs +++ b/main/src/domain/lua_module_container.rs @@ -49,7 +49,7 @@ where normalized_path: Option, display_name: String, code: &str, - ) -> anyhow::Result> { + ) -> anyhow::Result { execute_as_module( lua, normalized_path, @@ -92,7 +92,7 @@ fn find_and_execute_module<'lua>( finder: impl LuaModuleFinder + Clone + 'static, accumulator: SharedAccumulator, required_path: &str, -) -> anyhow::Result> { +) -> anyhow::Result { // Validate let root_info = || format!("\n\nModule root path: {}", finder.module_root_path()); let path = Utf8Path::new(required_path); @@ -168,7 +168,7 @@ fn execute_as_module<'lua>( code: &str, finder: Result, accumulator: SharedAccumulator, -) -> anyhow::Result> { +) -> anyhow::Result { let env = create_fresh_environment(lua, true)?; let require = create_require_function(lua, finder, accumulator.clone())?; env.set("require", require)?; @@ -207,7 +207,7 @@ fn create_require_function<'lua>( lua: &'lua Lua, finder: Result, accumulator: SharedAccumulator, -) -> anyhow::Result> { +) -> anyhow::Result { let require = lua.create_function_mut(move |lua, required_path: String| { let finder = finder.clone().map_err(mlua::Error::runtime)?; let value = diff --git a/main/src/domain/lua_support.rs b/main/src/domain/lua_support.rs index 5cc5672d6..6e2064f8b 100644 --- a/main/src/domain/lua_support.rs +++ b/main/src/domain/lua_support.rs @@ -48,8 +48,8 @@ impl SafeLua { &'a self, name: &str, code: &str, - env: Table<'a>, - ) -> anyhow::Result> { + env: Table, + ) -> anyhow::Result { let chunk = self .0 .load(code) @@ -65,8 +65,8 @@ impl SafeLua { &'a self, display_name: String, code: &str, - env: Table<'a>, - ) -> anyhow::Result> { + env: Table, + ) -> anyhow::Result { compile_and_execute(&self.0, display_name, code, env) } @@ -107,8 +107,8 @@ pub fn compile_and_execute<'a>( lua: &'a Lua, display_name: String, code: &str, - env: Table<'a>, -) -> anyhow::Result> { + env: Table, +) -> anyhow::Result { let lua_chunk = lua .load(code) .set_name(display_name) @@ -147,7 +147,7 @@ fn build_safe_lua_env<'a>( lua: &'a Lua, original_env: Table, allow_side_effects: bool, -) -> anyhow::Result> { +) -> anyhow::Result { let safe_env = lua.create_table()?; for var in SAFE_LUA_VARS { copy_var_to_table(lua, &safe_env, &original_env, var)?; @@ -169,7 +169,7 @@ fn copy_var_to_table( if let Some(dot_index) = var.find('.') { // Nested variable let parent_var = &var[0..dot_index]; - let nested_dest_table = if let Ok(t) = dest_table.get::<_, Table>(parent_var) { + let nested_dest_table = if let Ok(t) = dest_table.get(parent_var) { t } else { let new_table = lua.create_table()?; diff --git a/main/src/domain/main_processor.rs b/main/src/domain/main_processor.rs index cca4a8158..8921e9e8e 100644 --- a/main/src/domain/main_processor.rs +++ b/main/src/domain/main_processor.rs @@ -87,7 +87,7 @@ pub struct MainProcessor { struct Basics { instance_id: InstanceId, unit_id: UnitId, - common_lua: EnumMap>>, + common_lua: EnumMap>, unit_container: &'static dyn UnitContainer, settings: BasicSettings, control_is_globally_enabled: bool, @@ -2935,7 +2935,7 @@ pub struct BasicSettings { #[derive(Clone, Debug, Default)] pub struct CompartmentSettings { - pub common_lua: Option>, + pub common_lua: Option, } #[derive( diff --git a/main/src/domain/midi_source.rs b/main/src/domain/midi_source.rs index b4f1f8125..abd8423fc 100644 --- a/main/src/domain/midi_source.rs +++ b/main/src/domain/midi_source.rs @@ -28,7 +28,7 @@ type ScriptType = CloneAsDefault>>; pub type MidiSource = helgoboss_learn::MidiSource; impl<'a> MidiSourceScript<'a> for ScriptType { - type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a, 'static>; + type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a>; fn execute( &self, diff --git a/main/src/domain/mode.rs b/main/src/domain/mode.rs index 96c5d2242..756c4c066 100644 --- a/main/src/domain/mode.rs +++ b/main/src/domain/mode.rs @@ -7,7 +7,7 @@ use helgoboss_learn::{FeedbackScript, FeedbackScriptInput, FeedbackScriptOutput, use std::borrow::Cow; use std::error::Error; -pub type RealearnModeContext<'a> = ModeContext>; +pub type RealearnModeContext<'a> = ModeContext>; /// See [`crate::domain::MidiSource`] for an explanation of the feedback script wrapping. type FeedbackScriptType = CloneAsDefault>>; @@ -23,7 +23,7 @@ impl FeedbackScriptType { } impl<'a> FeedbackScript<'a> for FeedbackScriptType { - type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a, 'static>; + type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a>; fn feedback( &self, diff --git a/main/src/domain/source.rs b/main/src/domain/source.rs index dcf8ffe25..8aa48c47a 100644 --- a/main/src/domain/source.rs +++ b/main/src/domain/source.rs @@ -1,4 +1,4 @@ use crate::domain::AdditionalLuaMidiSourceScriptInput; use helgoboss_learn::SourceContext; -pub type RealearnSourceContext<'a> = SourceContext>; +pub type RealearnSourceContext<'a> = SourceContext>; diff --git a/main/src/infrastructure/ui/import.rs b/main/src/infrastructure/ui/import.rs index 50dc646bd..b6f6053a4 100644 --- a/main/src/infrastructure/ui/import.rs +++ b/main/src/infrastructure/ui/import.rs @@ -371,7 +371,7 @@ fn execute_lua_import_script<'a>( code: &str, active_compartment: CompartmentKind, limit_execution_time: bool, -) -> anyhow::Result> { +) -> anyhow::Result { if limit_execution_time { lua.start_execution_time_limit_countdown(); }