/
theCounter_callback.dats
102 lines (87 loc) · 1.62 KB
/
theCounter_callback.dats
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(*
theCounter_callback
*)
(* ****** ****** *)
//
#define
ATS_MAINATSFLAG 1
#define
ATS_DYNLOADNAME
"theCounter_callback_start"
//
#define
ATS_STATIC_PREFIX "theCounter_callback_"
//
(* ****** ****** *)
//
#define
LIBATSCC2JS_targetloc
"$PATSHOME\
/contrib/libatscc2js/ATS2-0.3.2"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2JS}/staloadall.hats"
//
staload
"{$LIBATSCC2JS}/SATS/print.sats"
staload _(*anon*) =
"{$LIBATSCC2JS}/DATS/print.dats"
//
(* ****** ****** *)
extern
fun
theCounter_button_up_click(): void = "mac#"
extern
fun
theCounter_button_down_click(): void = "mac#"
extern
fun
theCounter_button_reset_click(): void = "mac#"
(* ****** ****** *)
local
val
theCount =
ref{int}(0)
fun
theCount_update() =
{
//
val n = theCount[]
//
val d0 = n%10 and d1 = n/10
val d0 = String(d0) and d1 = String(d1)
//
val theCount_p = $extval(ptr, "$(\"#theCount_p\")")
val ((*void*)) = $extmcall(void, theCount_p, "text", d1+d0)
} (* end of [theCount_update] *)
in (* in-of-local *)
implement
theCounter_button_up_click
((*void*)) = let
val () =
theCount[] :=
min(theCount[]+1, 99) in theCount_update()
end // end of [theCounter_button_up_click]
implement
theCounter_button_down_click
((*void*)) = let
val () =
theCount[] :=
max( 0, theCount[]-1) in theCount_update()
end // end of [theCounter_button_down_click]
implement
theCounter_button_reset_click
((*void*)) = let
val () = theCount[] := 0 in theCount_update()
end // end of [theCounter_button_down_click]
end // end of [local]
(* ****** ****** *)
%{$
//
theCounter_callback_start();
//
%} // end of [%{$]
(* ****** ****** *)
(* end of [theCounter_callback.dats] *)