Files
simple-rust-tests/__wasm/js-wasm/helloworld/src/lib.rs
2022-07-17 19:39:28 +08:00

17 lines
536 B
Rust

use js::*;
#[no_mangle]
pub fn main() {
// let's dynamically create a javascript function we can invoke to write logs
let fn_log = js!(r##"function(strPtr, strLen) {
console.log(this.readUtf8FromMemory(strPtr, strLen));
}"##);
// let fn_alert = js!(r##"function(strPtr, strLen) {
// alert(this.readUtf8FromMemory(strPtr, strLen));
// }"##);
let msg = "Hello World!";
fn_log.invoke_2(msg.as_ptr() as u32, msg.len() as u32);
// fn_alert.invoke_2(msg.as_ptr() as u32, msg.len() as u32);
}