ling_wasm/lib.rs
1// crates/ling-wasm/src/lib.rs — wasm-bindgen entry points for the Ling WebGL runner.
2
3use wasm_bindgen::prelude::*;
4
5/// Initialise the rendering context on the given OffscreenCanvas.
6/// Must be called once before run_program.
7#[wasm_bindgen(js_name = "init_canvas")]
8pub fn init_canvas(canvas: web_sys::OffscreenCanvas) {
9 console_error_panic_hook::set_once();
10 let _ = canvas; // WebGL2 init wired through runtime at call-time
11}
12
13/// Parse and execute a Ling source program.
14/// Graphics output is rendered via the context set up by init_canvas.
15#[wasm_bindgen(js_name = "run_program")]
16pub fn run_program(source: &str) {
17 if let Err(e) = ling::run(source) {
18 web_sys::console::error_1(&wasm_bindgen::JsValue::from_str(&e));
19 }
20}