The pong tutorial (https://labs.leaningtech.com/cheerp/tutorials/pong) shows how to handle interactions between JS and Wasm using static functions and global instances. What is the recommended approach for accessing member functions of dynamically created JS objects from Wasm?
Example code:
struct [[cheerp::genericjs]] Foo { client::HTMLElement* span; Foo() { span = client::document.createElement("span"); span->set_textContent("Foo"); client::document.get_body()->appendChild(span); } void makeBar() { span->set_textContent("Bar"); }}struct [[cheerp::wasm]] Bar { Foo* foo; // obviously does not compile Bar() { foo = new Foo(); foo->makeBar(); }}[[cheerp::wasm]]void webMain() { Bar* bar = new Bar();}
struct [[cheerp::genericjs]] Foo { client::HTMLElement* span; Foo() { span = client::document.createElement("span"); span->set_textContent("Foo"); client::document.get_body()->appendChild(span); } void makeBar() { span->set_textContent("Bar"); }}struct [[cheerp::wasm]] Bar { Foo* foo; // obviously does not compile Bar() { foo = new Foo(); foo->makeBar(); }}[[cheerp::wasm]]void webMain() { Bar* bar = new Bar();}
Home of WebVM, BrowserPod, Cheerp, CheerpJ, and CheerpX. Join developers discussing compilers, WebAssembly, virtual machines, and running real systems software in the browser.