From 7c202bd6e692dbd3d0b42f44357164216725b77f Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 1 Feb 2024 12:58:28 +0100 Subject: [PATCH] Add back support for process.exit and exit code --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lune/builtins/process/mod.rs | 8 ++++---- src/lune/mod.rs | 16 ++++++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 091c98e0..083dac80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1335,7 +1335,7 @@ dependencies = [ [[package]] name = "mlua-luau-runtime" version = "0.0.0" -source = "git+https://github.com/lune-org/mlua-luau-runtime?rev=a5ae251fa3d62bb023dfbfc8ef692b28ff7a9a16#a5ae251fa3d62bb023dfbfc8ef692b28ff7a9a16" +source = "git+https://github.com/lune-org/mlua-luau-runtime?rev=4117cfba75c6df50bd5b12a776ad33e768393753#4117cfba75c6df50bd5b12a776ad33e768393753" dependencies = [ "async-executor", "concurrent-queue", diff --git a/Cargo.toml b/Cargo.toml index 24f895fc..f1e66561 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } tokio = { version = "1.24", features = ["full", "tracing"] } os_str_bytes = { version = "6.4", features = ["conversions"] } -mlua-luau-runtime = { git = "https://github.com/lune-org/mlua-luau-runtime", rev = "a5ae251fa3d62bb023dfbfc8ef692b28ff7a9a16" } +mlua-luau-runtime = { git = "https://github.com/lune-org/mlua-luau-runtime", rev = "4117cfba75c6df50bd5b12a776ad33e768393753" } mlua = { version = "0.9.5", features = [ "async", "luau", diff --git a/src/lune/builtins/process/mod.rs b/src/lune/builtins/process/mod.rs index fe9dcc21..43d6f0d8 100644 --- a/src/lune/builtins/process/mod.rs +++ b/src/lune/builtins/process/mod.rs @@ -1,7 +1,7 @@ use std::{ env::{self, consts}, path, - process::Stdio, + process::{ExitCode, Stdio}, }; use mlua::prelude::*; @@ -61,9 +61,9 @@ pub fn create(lua: &Lua) -> LuaResult { .globals() .get::<_, LuaTable>("coroutine")? .get::<_, LuaFunction>("yield")?; - let set_scheduler_exit_code = lua.create_function(|_, _code: Option| { - // TODO: Implement this - // sched.set_exit_code(code.unwrap_or_default()); + let set_scheduler_exit_code = lua.create_function(|lua, code: Option| { + let code = code.map(ExitCode::from).unwrap_or_default(); + lua.set_exit_code(code); Ok(()) })?; let process_exit = lua diff --git a/src/lune/mod.rs b/src/lune/mod.rs index b9df79d0..e831baa9 100644 --- a/src/lune/mod.rs +++ b/src/lune/mod.rs @@ -69,11 +69,15 @@ impl Runtime { rt.run().await; - // TODO: Grab exit code that user set, if available - let res = rt.get_thread_result(id).unwrap(); - Ok(match res { - Ok(_) => ExitCode::SUCCESS, - Err(_) => ExitCode::FAILURE, - }) + if let Some(code) = rt.get_exit_code() { + Ok(code) + } else if let Some(res) = rt.get_thread_result(id) { + Ok(match res { + Ok(_) => ExitCode::SUCCESS, + Err(_) => ExitCode::FAILURE, + }) + } else { + Ok(ExitCode::SUCCESS) + } } }