Skip to content

Commit

Permalink
Add watching of rust wasm with cargo watch - rustwasm/wasm-pack#457
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Oct 30, 2022
1 parent 655ed62 commit a59a951
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"license": "MIT",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "yarn wasmwatch & vite",
"build": "tsc && vite build",
"preview": "vite preview",
"parceldev": "parcel index.html",
"parceldemo": "parcel input.html",
"test": "jest",
"wasmpack": "wasm-pack build"
"wasmpack": "wasm-pack build",
"wasmwatch": "cargo watch -w src/*.rs -s \"wasm-pack build\""
},
"devDependencies": {
"@types/jest": "^29.1.2",
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ pub fn add(a: i32, b: i32) -> i32 {
#[wasm_bindgen]
pub fn subtract(a: i32, b: i32) -> i32 {
return a - b;
}

#[wasm_bindgen]
pub fn multiply(a: i32, b: i32) -> i32 {
return a * b;
}

#[wasm_bindgen]
pub fn divide(a: i32, b: i32) -> i32 {
return a / b;
}
4 changes: 2 additions & 2 deletions src/pong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { MarshalInput } from './MarshalInput';
import { GamepadSnapshot } from './GamepadSnapshot';
import {clamp} from './lib';
import { Pog } from './types';
import {add, subtract } from '../pkg/hellowasm_bg.wasm'
import {add, subtract, multiply, divide} from '../pkg/hellowasm_bg.wasm'

console.log('nice', add(1,1), subtract(400, 100));
console.log('nice', add(1,1), subtract(400, 100), multiply(100,100), divide(20,10));

type GameState = {
leftPaddle: BoundingBox,
Expand Down

0 comments on commit a59a951

Please sign in to comment.