Fixed wasm build with string error and warning

This commit is contained in:
Sambo Chea 2020-08-20 16:17:44 +07:00
parent cc6b0c38db
commit e7b88b96e1
5 changed files with 24 additions and 20 deletions

View File

@ -3,6 +3,9 @@ name = "wasmweb-sample"
version = "0.1.0"
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
edition = "2018"
description = "Just WASM Sample for CUBETIQ Solution"
license = "MIT"
repository = "https://github.com/CUBETIQ/wasmweb-sample.git"
[dependencies.web-sys]
version = "0.3"
@ -40,3 +43,6 @@ wasm-bindgen-test = "0.3.13"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
[package.metadata.wasm-pack.profile.release]
wasm-opt = false

View File

@ -1,4 +1,5 @@
use wasm_bindgen::prelude::*;
use math;
extern crate web_sys;
@ -21,18 +22,13 @@ extern {
}
#[wasm_bindgen]
extern {
fn sum(a: i32, b: i32) -> i32;
}
#[wasm_bindgen]
pub fn greet() {
alert("Hey, CUBETIQ Solution!");
pub fn greet() -> String {
"Hey, CUBETIQ Solution!".into()
}
#[wasm_bindgen]
pub fn just_sum() -> i32 {
let sum = sum(100, 50);
let sum = math::sum(100, 50);
log(&format!("Just Sum {} + {} = {}", 100, 50, sum));
return sum;
}

View File

@ -2,5 +2,10 @@ use math;
fn main() {
let sum = math::sum(1, 2);
println!("Sum number {}", sum)
println!("Sum number {}", sum);
println!("Greetings, {}", welcome());
}
fn welcome() -> String {
return String::from("Hello, Sambo")
}

View File

@ -1,8 +1,8 @@
// import * as wasm from "hello-wasm-pack";
import * as wasm from "./../pkg/wasmweb_sample"
wasm.greet()
wasm.log("[WEB] external logging...")
const sum = wasm.just_sum()
console.log("Sum of number", sum)
// import * as wasm from 'wasmweb-sample'
//
// wasm.log("[WEB] external logging...")
//
// const greeting = wasm.greet()
// const sum = wasm.just_sum()
// console.log("Sum of number", sum)

View File

@ -33,8 +33,5 @@
"webpack": "^4.29.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
},
"dependencies": {
"wasmweb-sample": "file:../pkg"
}
}