Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smokku/gwg-bindgen
good-web-game + wasm-bindgen example
https://github.com/smokku/gwg-bindgen
ggez gwg javascript rust rust-lang wasm wasm-bindgen webassembly
Last synced: 10 days ago
JSON representation
good-web-game + wasm-bindgen example
- Host: GitHub
- URL: https://github.com/smokku/gwg-bindgen
- Owner: smokku
- License: mit
- Created: 2020-08-24T07:06:14.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-12T19:41:26.000Z (over 3 years ago)
- Last Synced: 2024-10-08T19:04:06.573Z (about 1 month ago)
- Topics: ggez, gwg, javascript, rust, rust-lang, wasm, wasm-bindgen, webassembly
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-quads - wasm-bindgen interop - good-web-game + [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) example (Example usage / Apps or visualizations: On top of macroquad)
README
# GWG + `wasm-bindgen` example
This experiment shows connecting [`wasm-bindgen`](https://rustwasm.github.io/docs/wasm-bindgen/)
generated code to a [`good-web-game`](https://github.com/not-fl3/good-web-game) application.It uses `simple_logger` crate to `log!` in native mode and `console_log` in WASM mode.
Both versions build from the same codebase. You should see gwg main-loop lifecycle
methods calls in console.It requires a modification in the bindgen generated `.js` file (see sed call below)
and a boilerplate plugin for `miniquad` wasm loader - see `index.html`.## Building
### Native
$ cargo run
Finished dev [unoptimized + debuginfo] target(s)
Running `target/debug/gwg_bindgen`### WASM
#### pre-req
$ rustup target add wasm32-unknown-unknown
info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
info: installing component 'rust-std' for 'wasm32-unknown-unknown'
$ cargo install wasm-bindgen-cli#### build & run
$ cargo build --release --target wasm32-unknown-unknown
Compiling gwg_bindgen v0.1.0 (gwg_bindgen)
Finished release [optimized] target(s)
$ wasm-bindgen --out-dir target --target web target/wasm32-unknown-unknown/release/gwg_bindgen.wasm
$ sed -i 's/import.*from .env.;/init.set_wasm = w => wasm = w;/;s/imports\[.env.\] =.*/return imports;/' target/gwg_bindgen.jsThen serve project dir to browser. i.e.
$ basic-http-server .
[INFO ] basic-http-server 0.8.1
[INFO ] addr: http://127.0.0.1:4000
[INFO ] root dir: .