blob: 1e9808dabf77d0b19bab1685dd41a56ccea5b318 (
plain)
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
|
#include <stdio.h>
#include <string.h>
#include <emscripten.h>
struct Class {
static Class *instance;
int x;
Class() : x(0) {}
~Class() { x = -9999; }
void print() {
printf("waka %d\n", x++);
if (x == 7 || x < 0) {
int result = x;
REPORT_RESULT();
emscripten_cancel_main_loop();
}
}
static void callback() {
instance->print();
}
void start() {
instance = this;
// important if we simulate an infinite loop here or not. With an infinite loop, the
// destructor should *NOT* have been called
emscripten_set_main_loop(Class::callback, 3, 1);
}
};
Class *Class::instance = NULL;
int main() {
Class().start();
return 1;
}
|