libs-imp-mujs.mkxl /size: 2813 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=libs-imp-mujs,
3
%D version=2020.02.08,
4
%D title=\CONTEXT\ Extra Modules,
5
%D subtitle=MuJS interpreter,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
%D Just an experiment:
15
%D
16
%D \starttyping
17
%D http://mujs.com
18
%D \stoptyping
19 20
\ifdefined
\ecmacode
21
\expandafter
\endinput
22
\fi
23 24
\registerctxluafile
{
libs
-
imp
-
mujs
}{}
25 26
\unprotect
27 28
% todo: environment
29 30
\let
\stopecmacode
\relax
31 32
\normalprotected\def
\startecmacode
% \stopecmacode
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
-- mujs.execute [[
71
-- something very bad: an error
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