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-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (git+https://github.com/0x5eal/mlua-luau-scheduler-exitstatus.git)",
"once_cell",
"reqwest",
"rustyline",
@ -1531,7 +1531,7 @@ dependencies = [
"lune-std-task",
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde",
"serde_json",
"tokio",
@ -1581,7 +1581,7 @@ dependencies = [
"lune-std-serde",
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest",
"tokio",
"tokio-tungstenite",
@ -1595,7 +1595,7 @@ dependencies = [
"directories",
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"os_str_bytes",
"pin-project",
"tokio",
@ -1618,7 +1618,7 @@ dependencies = [
"lune-roblox",
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell",
"rbx_cookie",
]
@ -1646,7 +1646,7 @@ dependencies = [
"dialoguer",
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio",
]
@ -1656,7 +1656,7 @@ version = "0.1.0"
dependencies = [
"lune-utils",
"mlua",
"mlua-luau-scheduler",
"mlua-luau-scheduler 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio",
]
@ -1779,6 +1779,22 @@ dependencies = [
"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]]
name = "mlua-sys"
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 {
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 {
MaterialColors::default()
unreachable!()
}
}

View file

@ -57,7 +57,7 @@ workspace = true
[dependencies]
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"
console = "0.15"

View file

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

View file

@ -1,7 +1,6 @@
#![allow(clippy::missing_panics_doc)]
use std::{
process::ExitCode,
rc::Rc,
sync::{
atomic::{AtomicBool, Ordering},
@ -9,7 +8,7 @@ use std::{
},
};
use mlua::Lua;
use mlua::{IntoLuaMulti as _, Lua, Value};
use mlua_luau_scheduler::Scheduler;
use super::{RuntimeError, RuntimeResult};
@ -82,7 +81,7 @@ impl Runtime {
&mut self,
script_name: impl AsRef<str>,
script_contents: impl AsRef<[u8]>,
) -> RuntimeResult<ExitCode> {
) -> RuntimeResult<(u8, Vec<Value>)> {
// Create a new scheduler for this run
let sched = Scheduler::new(&self.lua);
@ -101,16 +100,20 @@ impl Runtime {
.set_name(script_name.as_ref());
// 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;
// Return the exit code - default to FAILURE if we got any errors
Ok(sched.get_exit_code().unwrap_or({
if got_any_error.load(Ordering::SeqCst) {
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}))
let thread_res = match sched.get_thread_result(main_thread_id) {
Some(res) => res,
None => Value::Nil.into_lua_multi(&self.lua),
}?
.into_vec();
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 meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary");
let result = Runtime::new()
.with_args(args)
.run("STANDALONE", meta.bytecode)
.await;
let mut rt = Runtime::new().with_args(args);
let result = rt.run("STANDALONE", meta.bytecode).await;
Ok(match result {
Err(err) => {
eprintln!("{err}");
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(".lua")
.to_string();
let exit_code = lune.run(&script_name, &script).await?;
Ok(exit_code)
let (exit_code, _) = lune.run(&script_name, &script).await?;
Ok(ExitCode::from(exit_code))
}
)* }
}