Skip to content

Commit

Permalink
Add back support for process.exit and exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Feb 1, 2024
1 parent 53935bb commit 7c202bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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 @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/lune/builtins/process/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
env::{self, consts},
path,
process::Stdio,
process::{ExitCode, Stdio},
};

use mlua::prelude::*;
Expand Down Expand Up @@ -61,9 +61,9 @@ pub fn create(lua: &Lua) -> LuaResult<LuaTable> {
.globals()
.get::<_, LuaTable>("coroutine")?
.get::<_, LuaFunction>("yield")?;
let set_scheduler_exit_code = lua.create_function(|_, _code: Option<u8>| {
// TODO: Implement this
// sched.set_exit_code(code.unwrap_or_default());
let set_scheduler_exit_code = lua.create_function(|lua, code: Option<u8>| {
let code = code.map(ExitCode::from).unwrap_or_default();
lua.set_exit_code(code);
Ok(())
})?;
let process_exit = lua
Expand Down
16 changes: 10 additions & 6 deletions src/lune/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 7c202bd

Please sign in to comment.