From 925d0617dab119ad69054a8062b546e143cba0e3 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 27 Feb 2024 16:39:40 -0800 Subject: [PATCH] add glue to webonly interpreter --- packages/interpreter/src/unified_bindings.rs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/interpreter/src/unified_bindings.rs b/packages/interpreter/src/unified_bindings.rs index 236262138..ce3cf2866 100644 --- a/packages/interpreter/src/unified_bindings.rs +++ b/packages/interpreter/src/unified_bindings.rs @@ -8,6 +8,31 @@ use sledgehammer_bindgen::bindgen; pub const SLEDGEHAMMER_JS: &str = GENERATED_JS; +#[cfg(feature = "webonly")] +#[wasm_bindgen::prelude::wasm_bindgen(inline_js = r#" +export function save_template(channel, nodes, tmpl_id) { + channel.save_template(nodes, tmpl_id); +} +export function hydrate(channel, ids) { + channel.hydrate(ids); +} +export function get_node(channel, id) { + return channel.get_node(id); +} +export function initialize(channel, root, handler) { + channel.initialize(root, handler); +} +"#)] +extern "C" { + pub fn save_template(channel: &JSChannel, nodes: Vec, tmpl_id: u16); + + pub fn hydrate(channel: &JSChannel, ids: Vec); + + pub fn get_node(channel: &JSChannel, id: u32) -> Node; + + pub fn initialize(channel: &JSChannel, root: Node, handler: &Function); +} + #[bindgen(module)] mod js { // Load in the JavaScript file with all the imports