diff options
author | Hans Hagen <pragma@wxs.nl> | 2020-02-16 10:59:14 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2020-02-16 10:59:14 +0100 |
commit | 8e11d447440b44990432ac838953a8cde4ef914f (patch) | |
tree | f30b2ff2d8a10f1aff50e1522d968618a97f067c /tex/context/base/mkiv/libs-imp-mujs.mkxl | |
parent | 43fc66771a0c9d27cc0b7fe7a69392ea313bd0ca (diff) | |
download | context-8e11d447440b44990432ac838953a8cde4ef914f.tar.gz |
2020-02-11 16:39:00
Diffstat (limited to 'tex/context/base/mkiv/libs-imp-mujs.mkxl')
-rw-r--r-- | tex/context/base/mkiv/libs-imp-mujs.mkxl | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/libs-imp-mujs.mkxl b/tex/context/base/mkiv/libs-imp-mujs.mkxl new file mode 100644 index 000000000..0f278dff5 --- /dev/null +++ b/tex/context/base/mkiv/libs-imp-mujs.mkxl @@ -0,0 +1,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}{} + +\unprotect + +% todo: environment + +\let\stopecmacode\relax + +\normalprotected\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 |