Currently, MathCATDemo uses a webassembly rust build and wraps stuff around that using whatever interface to it needs. It would be much better to make the interface explicit and then build the demo on that in Javascript.
This would parallel what is done for C, Python, etc.
This should be a relatively easy project. The basics are that for every MathCAT interface function, a Javascript callable function should be defined. This is done via
For example
pub fn set_mathml(mathml_str: String) -> Result<String>
probably wants to have some code like:
#[wasm_bindgen]
pub fn setMathML(mathml: &str) -> Result<String> {
return libmathcat::set_mathml(mathml);
}
Note that Javascript convention seems to be camelCase whereas rust convention is snake_case. Hence the exposed function is called setMathML and that is what Javascript should call.
Near the top of the file there needs to be
use wasm_bindgen::prelude::*;
use libmathcat::*;
From the little I've read, it seems that the Result<String> return is magically handled by wasm-bindgen and the JavaScript code and if there is an error, standard JS exception handling works.
A good reference is The wasm-bindgen Guide. Among other things, it mentions using how to use webpack to package it all up.
Currently, MathCATDemo uses a webassembly rust build and wraps stuff around that using whatever interface to it needs. It would be much better to make the interface explicit and then build the demo on that in Javascript.
This would parallel what is done for C, Python, etc.
This should be a relatively easy project. The basics are that for every MathCAT interface function, a Javascript callable function should be defined. This is done via
For example
probably wants to have some code like:
Note that Javascript convention seems to be camelCase whereas rust convention is snake_case. Hence the exposed function is called
setMathMLand that is what Javascript should call.Near the top of the file there needs to be
From the little I've read, it seems that the
Result<String>return is magically handled by wasm-bindgen and the JavaScript code and if there is an error, standard JS exception handling works.A good reference is The wasm-bindgen Guide. Among other things, it mentions using how to use webpack to package it all up.