wasm-bindgen/examples
Alex Crichton b9dc937d73 Refactor WebIDL code generation
This commit refactors WebIDL code generation to walk over the fields of
`FirstPassRecord` instead of walking the AST again. This helps remove
redundancies like checking `is_chrome_only` as well as revisiting partial
interfaces and such. This should make it more clear that the first pass's job is
to walk the AST and collect all relevant information, while the codegen pass is
purely about appending items to a `Program`.

Additionally this refactoring will also soon be used to prepare different data
structures for operation overloadings, avoiding the need to walk those ASTs
twice.
2018-08-30 12:54:54 -07:00
..
add Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
asm.js Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
canvas web-sys: Add support for Global-scope methods 2018-08-28 17:20:31 -07:00
char Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
closures Move the unsize feature behind a nightly Cargo feature 2018-08-19 14:45:59 -07:00
comments Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
console_log Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
dom Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
fetch web-sys: Add support for Global-scope methods 2018-08-28 17:20:31 -07:00
guide-supported-types-examples Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
hello_world Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
import_js Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
julia_set Refactor WebIDL code generation 2018-08-30 12:54:54 -07:00
math Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
no_modules Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
performance Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
smorgasboard Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
wasm-in-wasm Remove use_extern_macros features 2018-08-19 14:33:01 -07:00
webaudio Skip args in overloaded method names if all same 2018-08-20 10:30:02 -07:00
README.md Make the list of examples alphabetical, and add webaudio and fetch examples 2018-08-19 18:41:02 -04:00

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:

  • add - an example of generating a tiny wasm binary, one that only adds two numbers.
  • asm.js - an example of using the wasm2asm tool from binaryen to convert the generated WebAssembly to normal JS
  • char - an example of passing the rust char type to and from the js string type
  • closures - an example of how to invoke functions like setInterval or use the onclick property in conjunction with closures.
  • comments - an example of how Rust comments are copied into js bindings
  • console_log - a showcase of #[wasm_bindgen] importing classes and how to bind console.log
  • dom - an example of accessing the global document object and appending HTML to it
  • fetch -- how to use the Fetch API to make async http requests
  • hello_world - the "hello world" of #[wasm_bindgen], aka throwing up a dialog greeting you
  • import_js - an example of importing local JS functionality into a crate
  • math - like console_log except showing how to import Math-related functions instead
  • no_modules - an example of how to use the --no-modules flag to the wasm-bindgen CLI tool
  • performance - how to import APIs like performance.now() and time various operations in Rust
  • smorgasboard - 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 JS
  • wasm-in-wasm - how to interact with namespaced APIs like WebAssembly.Module and shows off creation of a WebAssembly module from Rust
  • webaudio - how to use the Web Audio APIs to generate sounds