1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20\ifdefined
\ecmacode
21 \expandafter
\endinput
22\fi
23
24\registerctxluafile
{
libs
imp
mujs
}{}
25
26\unprotect
27
28
29
30\let
\stopecmacode
\relax
31
32\normalprotected\def
\startecmacode
33 {
\begingroup
34 \obeylualines
35 \obeyluatokens
36 \luat_start_ecma_code_indeed
}
37
38\def
\luat_start_ecma_code_indeed
#
1
\stopecmacode
39 {
\normalexpanded
{
\endgroup\noexpand
\ecmacode
{
#
1
}}}
40
41\protect
42
43\continueifinputfile
{
libs
imp
mujs
.
mkxl
}
44
45\usemodule
[
article
basic
,
abbreviations
logos
]
46
47\starttext
48
49\startbuffer
50\startluacode
51 local
mujs
=
require
(
"
libs-imp-mujs
"
)
52
53 mujs
.
execute
[
[
54 var
MyMax
=
1000
;
55 ]
]
56
57 mujs
.
execute
[
[
58 console
(
"
Example One!
"
)
;
59 texsprint
(
"
\\startpacked
"
)
;
60 for
(
var
i
=
1
;
i
<
=
MyMax
;
i
=
i
+
1
)
{
61 texprint
(
62 "
This is a buildbot compilation challenge for Mojca:
"
63 .
concat
(
Math
.
sqrt
(
i
/
MyMax
)
)
64 .
concat
(
"
!\\par
"
)
65 )
;
66 }
67 texsprint
(
"
\\stoppacked
"
)
;
68 ]
]
69
70
71
72
73\stopluacode
74
75\startecmacode
76 console
("
Example
Two
!
")
;
77 for
(
var
i
=
1
;
i
<=
MyMax
;
i
=
i
1
)
{
78 texsprint
(
79 "
And
an
opportunity
for
Alan
to
attract
highschool
students
to
\\
TeX
:
"
80 .
concat
(
i
)
81 .
concat
("
!
")
82 )
;
83 }
84\stopecmacode
85
86\ecmacode
{
87 console
("
Example
Three
!
")
;
88 texprint
("
And
otherwise
a
way
to
prototype
\\
JAVASCRIPT
\\
code
in
\\
PDF
.
")
89}
90
91\startecmacode
92 var
f
=
File
("
libs
imp
mujs
.
mkxl
"
,
"
r
")
;
93 console
(
f
)
;
94 var
l
=
f
.
read
(
4
0
0
)
;
95 var
l
=
f
.
read
("
*
a
")
;
96 console
(
l
)
;
97 f
.
close
()
;
98\stopecmacode
99
100\startecmacode
101 console
("
Example
Four
!
")
;
102 texsprint
("
\\
startMPcode
"
103 .
concat
(
fill
fullcircle
scaled
6
cm
withcolor
"
darkred
"
;
)
104 .
concat
(
fill
fullcircle
scaled
4
cm
withcolor
"
darkgreen
"
;
)
105 .
concat
(
fill
fullcircle
scaled
2
cm
withcolor
"
darkblue
"
;
)
106 .
concat
("
\\
stopMPcode
")
107 )
;
108\stopecmacode
109
110\startluacode
111 context
.
startMPcode
(
)
112 context
(
'
fill fullcircle scaled 6cm withcolor "middlecyan";
'
)
113 context
(
'
fill fullcircle scaled 4cm withcolor "middlemagenta";
'
)
114 context
(
'
fill fullcircle scaled 2cm withcolor "middleyellow";
'
)
115 context
.
stopMPcode
(
)
116\stopluacode
117\stopbuffer
118
119\typebuffer
\page
\getbuffer
120
121\stoptext
122