aplang_lib/
output.rs

1#[cfg(feature = "wasm")]
2#[macro_export]
3macro_rules! display {
4    ($($tee:tt)*) => {
5        $crate::wasm::OUT.with(|out| {
6            if let Some(ref callback) = *out.borrow() {
7                let this = wasm_bindgen::JsValue::NULL;
8
9                callback.call2(
10                    &this,
11                    &wasm_bindgen::JsValue::from_str(format!($($tee)*).as_str()),
12                    &wasm_bindgen::JsValue::from_bool(false),
13                )
14                .expect("could not make call to stdout");
15            };
16        })
17    };
18}
19
20#[cfg(not(feature = "wasm"))]
21#[macro_export]
22macro_rules! display {
23    ($($tee:tt)*) => {
24        print!($($tee)*)
25    };
26}
27
28#[cfg(feature = "wasm")]
29#[macro_export]
30macro_rules! display_error {
31    ($($tee:tt)*) => {
32        $crate::wasm::OUT.with(|out| {
33            if let Some(ref callback) = *out.borrow() {
34                let this = wasm_bindgen::JsValue::NULL;
35
36                callback.call2(
37                    &this,
38                    &wasm_bindgen::JsValue::from_str(format!($($tee)*).as_str()),
39                    &wasm_bindgen::JsValue::from_bool(true),
40                )
41                .expect("could not make call to stdout");
42            };
43        })
44    };
45}
46
47#[cfg(not(feature = "wasm"))]
48#[macro_export]
49macro_rules! display_error {
50    ($($tee:tt)*) => {
51        eprint!($($tee)*)
52    };
53}