From 93fa14d832b26bab9a45eb4d56136104a6080cf9 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Wed, 16 Oct 2024 21:41:16 +0200 Subject: [PATCH] Revert some unnecessary stylistic changes --- crates/lune-roblox/src/instance/terrain.rs | 7 ++----- crates/lune/src/cli/run.rs | 11 +++++++---- crates/lune/src/rt/runtime.rs | 8 +++----- crates/lune/src/standalone/mod.rs | 1 + crates/mlua-luau-scheduler/src/functions.rs | 4 ---- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/lune-roblox/src/instance/terrain.rs b/crates/lune-roblox/src/instance/terrain.rs index d4ff227..8d77008 100644 --- a/crates/lune-roblox/src/instance/terrain.rs +++ b/crates/lune-roblox/src/instance/terrain.rs @@ -27,13 +27,10 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(methods: &mut M) } fn get_or_create_material_colors(instance: &Instance) -> MaterialColors { - if let Variant::MaterialColors(inner) = instance - .get_property("MaterialColors") - .unwrap_or(Variant::MaterialColors(MaterialColors::default())) - { + if let Some(Variant::MaterialColors(inner)) = instance.get_property("MaterialColors") { inner } else { - unreachable!() + MaterialColors::default() } } diff --git a/crates/lune/src/cli/run.rs b/crates/lune/src/cli/run.rs index 41c4c27..6267ed7 100644 --- a/crates/lune/src/cli/run.rs +++ b/crates/lune/src/cli/run.rs @@ -7,9 +7,10 @@ use tokio::{ io::{stdin, AsyncReadExt as _}, }; -use super::utils::files::{discover_script_path_including_lune_dirs, strip_shebang}; use lune::Runtime; +use super::utils::files::{discover_script_path_including_lune_dirs, strip_shebang}; + /// Run a script #[derive(Debug, Clone, Parser)] pub struct RunCommand { @@ -39,11 +40,13 @@ impl RunCommand { (file_display_name, file_contents) }; - // Create a new lune object with all globals & run the script - let mut runtime = Runtime::new().with_args(self.script_args); - let result = runtime + // Create a new lune runtime with all globals & run the script + let mut rt = Runtime::new().with_args(self.script_args); + + let result = rt .run(&script_display_name, strip_shebang(script_contents)) .await; + Ok(match result { Err(err) => { eprintln!("{err}"); diff --git a/crates/lune/src/rt/runtime.rs b/crates/lune/src/rt/runtime.rs index 51817aa..31e5b03 100644 --- a/crates/lune/src/rt/runtime.rs +++ b/crates/lune/src/rt/runtime.rs @@ -144,7 +144,6 @@ impl Runtime { script_name: impl AsRef, script_contents: impl AsRef<[u8]>, ) -> RuntimeResult<(u8, Vec)> { - // Create a new scheduler for this run let lua = self.inner.lua(); let sched = self.inner.scheduler(); @@ -165,17 +164,16 @@ impl Runtime { let main_thread_id = sched.push_thread_back(main, ())?; sched.run().await; - let thread_res = match sched.get_thread_result(main_thread_id) { + let main_thread_res = match sched.get_thread_result(main_thread_id) { Some(res) => res, None => LuaValue::Nil.into_lua_multi(lua), - }? - .into_vec(); + }?; Ok(( sched .get_exit_code() .unwrap_or(u8::from(got_any_error.load(Ordering::SeqCst))), - thread_res, + main_thread_res.into_vec(), )) } } diff --git a/crates/lune/src/standalone/mod.rs b/crates/lune/src/standalone/mod.rs index 805eb95..40321dd 100644 --- a/crates/lune/src/standalone/mod.rs +++ b/crates/lune/src/standalone/mod.rs @@ -30,6 +30,7 @@ pub async fn run(patched_bin: impl AsRef<[u8]>) -> Result { let meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary"); let mut rt = Runtime::new().with_args(args); + let result = rt.run("STANDALONE", meta.bytecode).await; Ok(match result { diff --git a/crates/mlua-luau-scheduler/src/functions.rs b/crates/mlua-luau-scheduler/src/functions.rs index 06e5c25..920cc85 100644 --- a/crates/mlua-luau-scheduler/src/functions.rs +++ b/crates/mlua-luau-scheduler/src/functions.rs @@ -1,15 +1,11 @@ -#![allow(unused_imports)] #![allow(clippy::too_many_lines)] -use std::process::{ExitCode, ExitStatus}; - use mlua::prelude::*; use crate::{ error_callback::ThreadErrorCallback, queue::{DeferredThreadQueue, SpawnedThreadQueue}, result_map::ThreadResultMap, - scheduler::Scheduler, thread_id::ThreadId, traits::LuaSchedulerExt, util::{is_poll_pending, LuaThreadOrFunction, ThreadResult},