@@ -265,6 +265,7 @@ macro_rules! janet_mod {
265265/// jpanic!(4); // In simple cases you can use any type that Janet implements From trait
266266/// jpanic!("this is a {} {message}", "fancy", message = "message");
267267/// ```
268+ #[ cfg( not( feature = "std" ) ) ]
268269#[ macro_export]
269270macro_rules! jpanic {
270271 ( ) => {
@@ -274,7 +275,34 @@ macro_rules! jpanic {
274275 $crate:: util:: _panic( $crate:: Janet :: from( $msg) ) ;
275276 } ;
276277 ( $msg: expr, $( $arg: tt) +) => {
277- $crate:: util:: _panic( $crate:: Janet :: from( alloc:: format!( $msg, $( $arg) +) . as_str( ) ) ) ;
278+ $crate:: util:: _panic( $crate:: Janet :: from( :: alloc:: format!( $msg, $( $arg) +) . as_str( ) ) ) ;
279+ } ;
280+ }
281+
282+ /// Causes a panic in the Janet side. Diferently of the Rust `panic!` macro, this macro
283+ /// does **not** terminate the current thread. Instead, it sends a error signal with the
284+ /// passed message where the Janet runtime takes care to properly exit.
285+ ///
286+ /// # Examples
287+ /// ```ignore
288+ /// use janetrs::jpanic;
289+ /// # let _client = janetrs::client::JanetClient::init().unwrap();
290+ /// jpanic!();
291+ /// jpanic!("this is a terrible mistake!");
292+ /// jpanic!(4); // In simple cases you can use any type that Janet implements From trait
293+ /// jpanic!("this is a {} {message}", "fancy", message = "message");
294+ /// ```
295+ #[ cfg( feature = "std" ) ]
296+ #[ macro_export]
297+ macro_rules! jpanic {
298+ ( ) => {
299+ $crate:: util:: _panic( $crate:: Janet :: from( "explicity panic" ) ) ;
300+ } ;
301+ ( $msg: expr $( , ) ?) => {
302+ $crate:: util:: _panic( $crate:: Janet :: from( $msg) ) ;
303+ } ;
304+ ( $msg: expr, $( $arg: tt) +) => {
305+ $crate:: util:: _panic( $crate:: Janet :: from( :: std:: format!( $msg, $( $arg) +) . as_str( ) ) ) ;
278306 } ;
279307}
280308
0 commit comments