additional CLI JS runtime notes
This commit is contained in:
parent
27efbe8cd0
commit
d5f992c28c
|
@ -10,3 +10,7 @@ For use in the Rust Ludus backend.
|
|||
* The canonical reference for all this is https://rustwasm.github.io/wasm-bindgen/introduction.html.
|
||||
* Look into what thi.ng does with Zig in its WASM packages: https://github.com/thi-ng/umbrella/tree/develop/packages, especially https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api.
|
||||
- It's looking like `--target web` is the most appropriate to use in 2024, since they use ES modules and not CommonJS, which is what everything else uses (and necessitates the build step). See https://rustwasm.github.io/wasm-pack/book/commands/build.html.
|
||||
- Bun can run the `index.js` file just fine.
|
||||
- Deno can, too, but it requires file read access, since that's kind of Deno's thing.
|
||||
- Node cannot. See https://rustwasm.github.io/wasm-pack/book/prerequisites/considerations.html. You have to polyfill `fetch` with `node-fetch` (https://github.com/node-fetch/node-fetch).
|
||||
* Obligatory: stop trying to make fetch happen.
|
||||
|
|
|
@ -5,6 +5,7 @@ use wasm_bindgen::prelude::*;
|
|||
#[wasm_bindgen(module = "/things.js")]
|
||||
extern "C" {
|
||||
fn foo() -> String;
|
||||
fn print(s: String);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -15,6 +16,8 @@ extern "C" {
|
|||
// without the line in Cargo.toml, this throws a lint warning
|
||||
#[wasm_bindgen]
|
||||
pub fn greet() {
|
||||
let from_js = foo();
|
||||
alert(format!("Hello, {from_js}"));
|
||||
let s = foo();
|
||||
let out = format!("Hi there from Rust. I got {s}");
|
||||
alert(out.clone());
|
||||
print(out);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user