summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/libs-imp-mujs.mkxl
blob: a8fe5801f39c812851331d70a2e0ef64bcdb379a (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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%D \module
%D   [       file=libs-imp-mujs,
%D        version=2020.02.08,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=MuJS interpreter,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D Just an experiment:
%D
%D \starttyping
%D http://mujs.com
%D \stoptyping

\ifdefined\ecmacode
    \expandafter \endinput
\fi

\registerctxluafile{libs-imp-mujs}{autosuffix}

\unprotect

% todo: environment

\let\stopecmacode\relax

\protected\def\startecmacode % \stopecmacode
  {\begingroup
   \obeylualines
   \obeyluatokens
   \luat_start_ecma_code_indeed}

\def\luat_start_ecma_code_indeed#1\stopecmacode
  {\normalexpanded{\endgroup\noexpand\ecmacode{#1}}}

\protect

\continueifinputfile{libs-imp-mujs.mkxl}

\usemodule[article-basic,abbreviations-logos]

\starttext

\startbuffer
\startluacode
    local mujs = require("libs-imp-mujs")

    mujs.execute [[
        var MyMax = 1000;
    ]]

    mujs.execute [[
        console("Example One!");
        texsprint("\\startpacked");
        for (var i = 1; i <= MyMax; i = i + 1) {
            texprint(
                "This is a buildbot compilation challenge for Mojca: "
                .concat(Math.sqrt(i/MyMax))
                .concat("!\\par")
            );
        }
        texsprint("\\stoppacked");
    ]]

 -- mujs.execute [[
 --     something very bad: an error
 -- ]]
\stopluacode

\startecmacode
    console("Example Two!");
    for (var i = 1; i <= MyMax; i = i + 1) {
        texsprint(
            "And an opportunity for Alan to attract highschool students to \\TeX: "
            .concat(i)
            .concat("! ")
        );
    }
\stopecmacode

\ecmacode {
    console("Example Three!");
    texprint("And otherwise a way to prototype \\JAVASCRIPT\\ code in \\PDF.")
}

\startecmacode
    var f = File("libs-imp-mujs.mkxl","r");
    console(f);
 // var l = f.read(400);
    var l = f.read("*a");
    console(l);
    f.close();
\stopecmacode

\startecmacode
    console("Example Four!");
    texsprint("\\startMPcode "
      .concat('  fill fullcircle scaled 6cm withcolor "darkred";')
      .concat('  fill fullcircle scaled 4cm withcolor "darkgreen";')
      .concat('  fill fullcircle scaled 2cm withcolor "darkblue";')
      .concat("\\stopMPcode ")
    );
\stopecmacode

\startluacode
    context.startMPcode()
        context('fill fullcircle scaled 6cm withcolor "middlecyan";')
        context('fill fullcircle scaled 4cm withcolor "middlemagenta";')
        context('fill fullcircle scaled 2cm withcolor "middleyellow";')
    context.stopMPcode()
\stopluacode
\stopbuffer

\typebuffer \page \getbuffer

\stoptext