Add console and web sys for logging
This commit is contained in:
parent
b04176248d
commit
9a7f63c7bc
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptLibraryMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -4,6 +4,12 @@ version = "0.1.0"
|
|||||||
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
|
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies.web-sys]
|
||||||
|
version = "0.3"
|
||||||
|
features = [
|
||||||
|
"console",
|
||||||
|
]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
13
run
13
run
@ -1,5 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "build wasm pack..."
|
||||||
|
wasm-pack build
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo -e "\e[32mBuild successfully!"
|
||||||
|
else
|
||||||
|
echo -e "\e[31mBuild failed for wasm-pack into script!" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\e[39m"
|
||||||
|
|
||||||
echo "install deps...."
|
echo "install deps...."
|
||||||
cd www && npm install
|
cd www && npm install
|
||||||
|
|
||||||
|
16
src/lib.rs
16
src/lib.rs
@ -1,13 +1,20 @@
|
|||||||
mod utils;
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
extern crate web_sys;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
// allocator.
|
// allocator.
|
||||||
#[cfg(feature = "wee_alloc")]
|
#[cfg(feature = "wee_alloc")]
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
|
#[wasm_bindgen(start)]
|
||||||
|
pub fn run() {
|
||||||
|
log("[WASM] internal logging...");
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern {
|
||||||
fn alert(s: &str);
|
fn alert(s: &str);
|
||||||
@ -17,3 +24,8 @@ extern {
|
|||||||
pub fn greet() {
|
pub fn greet() {
|
||||||
alert("Hey, CUBETIQ Solution!");
|
alert("Hey, CUBETIQ Solution!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn log(s: &str) {
|
||||||
|
web_sys::console::log_1(&s.into());
|
||||||
|
}
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
import * as wasm from "./../pkg/wasmweb_sample"
|
import * as wasm from "./../pkg/wasmweb_sample"
|
||||||
|
|
||||||
wasm.greet()
|
wasm.greet()
|
||||||
|
wasm.log("[WEB] external logging...")
|
||||||
|
Loading…
Reference in New Issue
Block a user