-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
62 lines (51 loc) · 1.26 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
mod utils;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
mod universe;
use universe::Universe;
#[wasm_bindgen]
extern {
fn alert(s: &str);
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen]
pub fn greet() {
alert("Hello, world! wasm-glife!");
let mut universe = universe::Universe::new(8, 8);
log(&universe.sum().to_string());
log(&universe.to_string());
universe.tick();
log(&universe.sum().to_string());
log(&universe.to_string());
}
#[wasm_bindgen]
pub struct Game {
universe: Universe,
}
#[wasm_bindgen]
impl Game {
pub fn new(width: u32, height: u32) -> Game {
Game {
universe: Universe::new(width, height)
}
}
#[allow(non_snake_case)]
pub fn toString(&self) -> String {
self.universe.to_string()
}
pub fn tick(&mut self) {
self.universe.tick();
}
#[allow(non_snake_case)]
pub fn isChanged(&self, i: usize) -> bool {
self.universe.changed(i)
}
pub fn toggle(&mut self, i: usize) {
self.universe.toggle(i);
}
}