mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 15:31:48 +03:00
19d6cf1488
* backend comments complete * better matching * gen comments * Add example * Move test bindings gen to own fn * move build step into build fn * add fn to read js, refactor gen_bindings/test to allow for this * Add comments test * Update readmes * add comments to travis * fix broken tests * +x on build.sh * fix wbg cmd in build.sh * Address fitzgen's comments
2.0 KiB
2.0 KiB
Examples
This directory contains a number of examples of the #[wasm_bindgen]
macro and
how to display them in the browser. Each directory contains a README with a link
to https://webassembly.studio so you can also explore the example online
(apologies if they're out of sync!), and each directory also contains a
build.sh
which assembles all the relevant files locally. If you open up
index.html
in a web browser you should be able to see everything in action
when using build.sh
!
The examples here are:
hello_world
- the "hello world" of#[wasm_bindgen]
, aka throwing up a dialog greeting youconsole_log
- a showcase of#[wasm_bindgen]
importing classes and how to bindconsole.log
math
- likeconsole_log
except showing how to import Math-related functions insteaddom
- an example of accessing the globaldocument
object and appending HTML to itsmorgasboard
- a bunch of features all thrown into one, showing off the various capabilities of the#[wasm_bindgen]
macro and what you can do with it from JSperformance
- how to import APIs likeperformance.now()
and time various operations in Rustwasm-in-wasm
- how to interact with namespaced APIs likeWebAssembly.Module
and shows off creation of a WebAssembly module from Rustclosures
- an example of how to invoke functions likesetInterval
or use theonclick
property in conjunction with closures.no_modules
- an example of how to use the--no-modules
flag to thewasm-bindgen
CLI tooladd
- an example of generating a tiny wasm binary, one that only adds two numbers.asm.js
- an example of using thewasm2asm
tool from binaryen to convert the generated WebAssembly to normal JSchar
- an example of passing the rustchar
type to and from the jsstring
typeimport_js
- an example of importing local JS functionality into a cratecomments
- an example of how Rust comments are copied into js bindings