json_io, edit the
Cargo.tomlfile to add a
[lib]section and a
[dependencies]section. Besides the
wasm-bindgendependency, notice the
src/lib.rs. It shows four functions.
circumference()function takes one floating point number parameter, and returns a floating number value. Notice that the floating number type is not natively supported in SSVM, but is supported here via JSON.
area()function takes two floating point numbers (the width and length of a rectangle) and returns a floating point number (the area of the rectangle).
solve()function takes three floating point numbers (parameters of a quadratic equation), and returns two floating point numbers and a boolean (the roots or solutions to the equation and whether the equation has real roots).
draw()function takes two structs (
Point) and a string, and returns a struct (
draw()example is the same as the
draw_line()example from the last article, but the input argument is structured into a single JSON tuple.
.wasmfile is the WebAssembly bytecode program, and the
app.jsin Node.js environment as follows.