-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- When Rust panics, it doesn't exit helpfully by default. This function gives | ||
-- the Rust side an external function it can call with details of the panic, | ||
-- so the error can be emitted on the Luau side instead. | ||
|
||
return function(extern_fns) | ||
local current_panic = nil | ||
function extern_fns.panic_reporter( | ||
len_or_byte: number | ||
): () | ||
if current_panic == nil then | ||
current_panic = { | ||
len = len_or_byte, | ||
bytes = "" | ||
} | ||
else | ||
current_panic.bytes ..= string.char(len_or_byte) | ||
if #current_panic.bytes == current_panic.len then | ||
error(current_panic.bytes, 0) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This forwards on any panics to the Luau side, where they can become visible | ||
// in the output. | ||
|
||
use std::panic; | ||
|
||
extern "C" { | ||
fn panic_reporter( | ||
len_or_byte: u32 | ||
); | ||
} | ||
|
||
pub fn connect() { | ||
panic::set_hook( | ||
Box::new(|panic| { | ||
let foo = format!("{panic}"); | ||
unsafe { panic_reporter(foo.len() as u32); } | ||
foo.bytes().for_each(|byte| unsafe { panic_reporter(byte as u32); }); | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters