Properly report panic by resuming unwind

This commit is contained in:
2025-06-28 04:11:33 +10:00
parent 5f1f6dab7a
commit 6a4c726965
6 changed files with 15 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
use luajit::Chunk;
use owo_colors::OwoColorize;
use std::{
fs,
fs, panic,
process::{self, ExitCode},
};
@@ -13,7 +13,7 @@ fn main() -> ExitCode {
rt.unhandled_error(error_cb).build().unwrap()
};
let path = "tests/test.lua";
let path = "tests/main.lua";
let main = lua.spawn(async move |s| {
if let Err(ref err) = s.load(Chunk::new(fs::read(path).unwrap()).path(path)) {
s.report_error(err);
@@ -30,7 +30,10 @@ fn main() -> ExitCode {
tokio.block_on(async move {
lua.await;
main.await.unwrap()
match main.await {
Ok(res) => res,
Err(err) => panic::resume_unwind(err.into_panic()),
}
})
}