refactor: migrate to new project structure (see de71558c5d)

This commit is contained in:
Erica Marigold 2024-05-12 19:59:24 +05:30
parent e0b9ceb86d
commit 962a2e50be
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
7 changed files with 52 additions and 33 deletions

30
Cargo.lock generated
View file

@ -1485,7 +1485,7 @@ dependencies = [
"lune-std", "lune-std",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (git+https://github.com/0x5eal/mlua-luau-scheduler-exitstatus.git)",
"once_cell", "once_cell",
"reqwest", "reqwest",
"rustyline", "rustyline",
@ -1531,7 +1531,7 @@ dependencies = [
"lune-std-task", "lune-std-task",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
@ -1581,7 +1581,7 @@ dependencies = [
"lune-std-serde", "lune-std-serde",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest", "reqwest",
"tokio", "tokio",
"tokio-tungstenite", "tokio-tungstenite",
@ -1595,7 +1595,7 @@ dependencies = [
"directories", "directories",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"os_str_bytes", "os_str_bytes",
"pin-project", "pin-project",
"tokio", "tokio",
@ -1618,7 +1618,7 @@ dependencies = [
"lune-roblox", "lune-roblox",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell", "once_cell",
"rbx_cookie", "rbx_cookie",
] ]
@ -1646,7 +1646,7 @@ dependencies = [
"dialoguer", "dialoguer",
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio", "tokio",
] ]
@ -1656,7 +1656,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"lune-utils", "lune-utils",
"mlua", "mlua",
"mlua-luau-scheduler", "mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio", "tokio",
] ]
@ -1779,6 +1779,22 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "mlua-luau-scheduler"
version = "0.0.2"
source = "git+https://github.com/0x5eal/mlua-luau-scheduler-exitstatus.git#82c8b902e09a21a9befa4e037beadefbe2360b7f"
dependencies = [
"async-executor",
"blocking",
"concurrent-queue",
"derive_more",
"event-listener 4.0.3",
"futures-lite",
"mlua",
"rustc-hash",
"tracing",
]
[[package]] [[package]]
name = "mlua-sys" name = "mlua-sys"
version = "0.5.2" version = "0.5.2"

View file

@ -27,11 +27,13 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(methods: &mut M)
} }
fn get_or_create_material_colors(instance: &Instance) -> MaterialColors { fn get_or_create_material_colors(instance: &Instance) -> MaterialColors {
if let Some(Variant::MaterialColors(material_colors)) = instance.get_property("MaterialColors") if let Variant::MaterialColors(inner) = instance
.get_property("MaterialColors")
.unwrap_or(Variant::MaterialColors(MaterialColors::default()))
{ {
material_colors inner
} else { } else {
MaterialColors::default() unreachable!()
} }
} }

View file

@ -57,7 +57,7 @@ workspace = true
[dependencies] [dependencies]
mlua = { version = "0.9.7", features = ["luau"] } mlua = { version = "0.9.7", features = ["luau"] }
mlua-luau-scheduler = "0.0.2" mlua-luau-scheduler = { git = "https://github.com/0x5eal/mlua-luau-scheduler-exitstatus.git" }
anyhow = "1.0" anyhow = "1.0"
console = "0.15" console = "0.15"

View file

@ -41,8 +41,8 @@ impl RunCommand {
}; };
// Create a new lune object with all globals & run the script // Create a new lune object with all globals & run the script
let result = Runtime::new() let mut runtime = Runtime::new().with_args(self.script_args);
.with_args(self.script_args) let result = runtime
.run(&script_display_name, strip_shebang(script_contents)) .run(&script_display_name, strip_shebang(script_contents))
.await; .await;
Ok(match result { Ok(match result {
@ -50,7 +50,7 @@ impl RunCommand {
eprintln!("{err}"); eprintln!("{err}");
ExitCode::FAILURE ExitCode::FAILURE
} }
Ok(code) => code, Ok((code, _)) => ExitCode::from(code),
}) })
} }
} }

View file

@ -1,7 +1,6 @@
#![allow(clippy::missing_panics_doc)] #![allow(clippy::missing_panics_doc)]
use std::{ use std::{
process::ExitCode,
rc::Rc, rc::Rc,
sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
@ -9,7 +8,7 @@ use std::{
}, },
}; };
use mlua::Lua; use mlua::{IntoLuaMulti as _, Lua, Value};
use mlua_luau_scheduler::Scheduler; use mlua_luau_scheduler::Scheduler;
use super::{RuntimeError, RuntimeResult}; use super::{RuntimeError, RuntimeResult};
@ -82,7 +81,7 @@ impl Runtime {
&mut self, &mut self,
script_name: impl AsRef<str>, script_name: impl AsRef<str>,
script_contents: impl AsRef<[u8]>, script_contents: impl AsRef<[u8]>,
) -> RuntimeResult<ExitCode> { ) -> RuntimeResult<(u8, Vec<Value>)> {
// Create a new scheduler for this run // Create a new scheduler for this run
let sched = Scheduler::new(&self.lua); let sched = Scheduler::new(&self.lua);
@ -101,16 +100,20 @@ impl Runtime {
.set_name(script_name.as_ref()); .set_name(script_name.as_ref());
// Run it on our scheduler until it and any other spawned threads complete // Run it on our scheduler until it and any other spawned threads complete
sched.push_thread_back(main, ())?; let main_thread_id = sched.push_thread_back(main, ())?;
sched.run().await; sched.run().await;
// Return the exit code - default to FAILURE if we got any errors let thread_res = match sched.get_thread_result(main_thread_id) {
Ok(sched.get_exit_code().unwrap_or({ Some(res) => res,
if got_any_error.load(Ordering::SeqCst) { None => Value::Nil.into_lua_multi(&self.lua),
ExitCode::FAILURE }?
} else { .into_vec();
ExitCode::SUCCESS
} Ok((
})) sched
.get_exit_code()
.unwrap_or(u8::from(got_any_error.load(Ordering::SeqCst))),
thread_res,
))
} }
} }

View file

@ -29,16 +29,14 @@ pub async fn run(patched_bin: impl AsRef<[u8]>) -> Result<ExitCode> {
let args = env::args().skip(1).collect::<Vec<_>>(); let args = env::args().skip(1).collect::<Vec<_>>();
let meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary"); let meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary");
let result = Runtime::new() let mut rt = Runtime::new().with_args(args);
.with_args(args) let result = rt.run("STANDALONE", meta.bytecode).await;
.run("STANDALONE", meta.bytecode)
.await;
Ok(match result { Ok(match result {
Err(err) => { Err(err) => {
eprintln!("{err}"); eprintln!("{err}");
ExitCode::FAILURE ExitCode::FAILURE
} }
Ok(code) => code, Ok((code, _)) => ExitCode::from(code),
}) })
} }

View file

@ -42,8 +42,8 @@ macro_rules! create_tests {
.trim_end_matches(".luau") .trim_end_matches(".luau")
.trim_end_matches(".lua") .trim_end_matches(".lua")
.to_string(); .to_string();
let exit_code = lune.run(&script_name, &script).await?; let (exit_code, _) = lune.run(&script_name, &script).await?;
Ok(exit_code) Ok(ExitCode::from(exit_code))
} }
)* } )* }
} }