Skip to content

Commit

Permalink
#1395 Fix build errors caused by new mlua
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Jan 16, 2025
1 parent eac19d6 commit 25b5497
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 46 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions main/src/application/unit_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3097,10 +3097,7 @@ impl RealearnControlSurfaceMainTaskSender {

const SESSION_GONE: &str = "session gone";

fn compile_common_lua(
compartment: CompartmentKind,
code: &str,
) -> anyhow::Result<mlua::Value<'static>> {
fn compile_common_lua(compartment: CompartmentKind, code: &str) -> anyhow::Result<mlua::Value> {
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| {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/flexible_midi_source_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions main/src/domain/lua_feedback_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
impl<'a> LuaFeedbackScript<'a> {
pub fn compile(lua: &'a SafeLua, lua_script: &str) -> anyhow::Result<Self> {
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())?;
Expand All @@ -42,7 +42,7 @@ impl<'lua> LuaFeedbackScript<'lua> {
fn feedback_internal(
&self,
input: FeedbackScriptInput,
additional_input: <LuaFeedbackScript<'lua> as FeedbackScript>::AdditionalInput,
additional_input: <LuaFeedbackScript<'a> as FeedbackScript<'a>>::AdditionalInput,
) -> anyhow::Result<FeedbackScriptOutput> {
let lua = self.lua.as_ref();
let value = lua.scope(|scope| {
Expand Down Expand Up @@ -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<Value<'lua>> {
impl IntoLua for LuaPropValue {
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
match self.0 {
PropValue::Normalized(p) => p.get().into_lua(lua),
PropValue::Index(i) => i.into_lua(lua),
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions main/src/domain/lua_midi_source_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions main/src/domain/lua_module_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
normalized_path: Option<String>,
display_name: String,
code: &str,
) -> anyhow::Result<Value<'lua>> {
) -> anyhow::Result<Value> {
execute_as_module(
lua,
normalized_path,
Expand Down Expand Up @@ -92,7 +92,7 @@ fn find_and_execute_module<'lua>(
finder: impl LuaModuleFinder + Clone + 'static,
accumulator: SharedAccumulator,
required_path: &str,
) -> anyhow::Result<Value<'lua>> {
) -> anyhow::Result<Value> {
// Validate
let root_info = || format!("\n\nModule root path: {}", finder.module_root_path());
let path = Utf8Path::new(required_path);
Expand Down Expand Up @@ -168,7 +168,7 @@ fn execute_as_module<'lua>(
code: &str,
finder: Result<impl LuaModuleFinder + Clone + 'static, &'static str>,
accumulator: SharedAccumulator,
) -> anyhow::Result<Value<'lua>> {
) -> anyhow::Result<Value> {
let env = create_fresh_environment(lua, true)?;
let require = create_require_function(lua, finder, accumulator.clone())?;
env.set("require", require)?;
Expand Down Expand Up @@ -207,7 +207,7 @@ fn create_require_function<'lua>(
lua: &'lua Lua,
finder: Result<impl LuaModuleFinder + Clone + 'static, &'static str>,
accumulator: SharedAccumulator,
) -> anyhow::Result<Function<'lua>> {
) -> anyhow::Result<Function> {
let require = lua.create_function_mut(move |lua, required_path: String| {
let finder = finder.clone().map_err(mlua::Error::runtime)?;
let value =
Expand Down
16 changes: 8 additions & 8 deletions main/src/domain/lua_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl SafeLua {
&'a self,
name: &str,
code: &str,
env: Table<'a>,
) -> anyhow::Result<Function<'a>> {
env: Table,
) -> anyhow::Result<Function> {
let chunk = self
.0
.load(code)
Expand All @@ -65,8 +65,8 @@ impl SafeLua {
&'a self,
display_name: String,
code: &str,
env: Table<'a>,
) -> anyhow::Result<Value<'a>> {
env: Table,
) -> anyhow::Result<Value> {
compile_and_execute(&self.0, display_name, code, env)
}

Expand Down Expand Up @@ -107,8 +107,8 @@ pub fn compile_and_execute<'a>(
lua: &'a Lua,
display_name: String,
code: &str,
env: Table<'a>,
) -> anyhow::Result<Value<'a>> {
env: Table,
) -> anyhow::Result<Value> {
let lua_chunk = lua
.load(code)
.set_name(display_name)
Expand Down Expand Up @@ -147,7 +147,7 @@ fn build_safe_lua_env<'a>(
lua: &'a Lua,
original_env: Table,
allow_side_effects: bool,
) -> anyhow::Result<Table<'a>> {
) -> anyhow::Result<Table> {
let safe_env = lua.create_table()?;
for var in SAFE_LUA_VARS {
copy_var_to_table(lua, &safe_env, &original_env, var)?;
Expand All @@ -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()?;
Expand Down
4 changes: 2 additions & 2 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct MainProcessor<EH: DomainEventHandler> {
struct Basics<EH: DomainEventHandler> {
instance_id: InstanceId,
unit_id: UnitId,
common_lua: EnumMap<CompartmentKind, Option<mlua::Value<'static>>>,
common_lua: EnumMap<CompartmentKind, Option<mlua::Value>>,
unit_container: &'static dyn UnitContainer,
settings: BasicSettings,
control_is_globally_enabled: bool,
Expand Down Expand Up @@ -2935,7 +2935,7 @@ pub struct BasicSettings {

#[derive(Clone, Debug, Default)]
pub struct CompartmentSettings {
pub common_lua: Option<mlua::Value<'static>>,
pub common_lua: Option<mlua::Value>,
}

#[derive(
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/midi_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ScriptType = CloneAsDefault<Option<FlexibleMidiSourceScript<'static>>>;
pub type MidiSource = helgoboss_learn::MidiSource<ScriptType>;

impl<'a> MidiSourceScript<'a> for ScriptType {
type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a, 'static>;
type AdditionalInput = AdditionalLuaMidiSourceScriptInput<'a>;

fn execute(
&self,
Expand Down
4 changes: 2 additions & 2 deletions main/src/domain/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use helgoboss_learn::{FeedbackScript, FeedbackScriptInput, FeedbackScriptOutput,
use std::borrow::Cow;
use std::error::Error;

pub type RealearnModeContext<'a> = ModeContext<AdditionalLuaFeedbackScriptInput<'a, 'static>>;
pub type RealearnModeContext<'a> = ModeContext<AdditionalLuaFeedbackScriptInput<'a>>;

/// See [`crate::domain::MidiSource`] for an explanation of the feedback script wrapping.
type FeedbackScriptType = CloneAsDefault<Option<LuaFeedbackScript<'static>>>;
Expand All @@ -23,7 +23,7 @@ impl FeedbackScriptType {
}

impl<'a> FeedbackScript<'a> for FeedbackScriptType {
type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a, 'static>;
type AdditionalInput = AdditionalLuaFeedbackScriptInput<'a>;

fn feedback(
&self,
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::domain::AdditionalLuaMidiSourceScriptInput;
use helgoboss_learn::SourceContext;

pub type RealearnSourceContext<'a> = SourceContext<AdditionalLuaMidiSourceScriptInput<'a, 'static>>;
pub type RealearnSourceContext<'a> = SourceContext<AdditionalLuaMidiSourceScriptInput<'a>>;
2 changes: 1 addition & 1 deletion main/src/infrastructure/ui/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn execute_lua_import_script<'a>(
code: &str,
active_compartment: CompartmentKind,
limit_execution_time: bool,
) -> anyhow::Result<mlua::Value<'a>> {
) -> anyhow::Result<mlua::Value> {
if limit_execution_time {
lua.start_execution_time_limit_countdown();
}
Expand Down

0 comments on commit 25b5497

Please sign in to comment.