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