summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl')
-rw-r--r--Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl104
1 files changed, 104 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl b/Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl
new file mode 100644
index 00000000000..158682399a8
--- /dev/null
+++ b/Master/texmf-dist/tex/context/base/mkxl/syst-lua.mkxl
@@ -0,0 +1,104 @@
+%D \module
+%D [ file=syst-lua,
+%D version=2008.01.25,
+%D title=\CONTEXT\ System Macros,
+%D subtitle=Helper macros based on \LUA,
+%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.
+
+\registerctxluafile{syst-lua}{autosuffix}
+
+\unprotect
+
+\permanent\def\expdoifelse#1#2{\clf_doifelsesame{#1}{#2}}
+\permanent\def\expdoif #1#2{\clf_doifsame {#1}{#2}}
+\permanent\def\expdoifnot #1#2{\clf_doifnotsame {#1}{#2}}
+
+%D Here is variant using a brainwave of the 12\high{+} hour \quotation {Long Road
+%D Out of Eden}\footnote {Eden being Backo\TeX\ 2018, where the virtues of the \type
+%D {\expanded} primitive were mentioned in talks.} trip. For now I don't really see
+%D other useful applications.
+
+\permanent\def\expandeddoifelse#1#2{\iftok{#1}{#2}\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
+\permanent\def\expandeddoif #1#2{\iftok{#1}{#2}\expandafter\firstofoneargument \else\expandafter\gobbleoneargument \fi}
+\permanent\def\expandeddoifnot #1#2{\iftok{#1}{#2}\expandafter\gobbleoneargument \else\expandafter\firstofoneargument \fi}
+
+% \testfeatureonce{100000}{\doifelse{hello world}{here i am}{}} % 0.3
+% \testfeatureonce{100000}{\expandabledoifelse{hello world}{here i am}{}} % 1.5
+
+\permanent\def\expdoifelsecommon#1#2{\clf_doifelsecommon{#1}{#2}}
+\permanent\def\expdoifelseinset #1#2{\clf_doifelseinset {#1}{#2}}
+
+\aliased\let\expdoifcommonelse\expdoifelsecommon
+\aliased\let\expdoifinsetelse \expdoifelseinset
+
+%D We define these here, just in case. This permits \typefile {self} otherwise
+%D nested b|/|e sep problems.
+
+\immutable\def\luastringsep{===}
+
+\immutable\edef\!!bs{[\luastringsep[}
+\immutable\edef\!!es{]\luastringsep]}
+
+\pushoverloadmode
+
+\permanent\protected\def\writestatus#1#2{\clf_writestatus{#1}{#2}}
+
+\popoverloadmode
+
+%D We can omit the tex.ctxcatcodes here as nowadays we seldom change the regime at
+%D the \TEX\ end:
+
+%def\luaexpr#1{\ctxlua{context (tostring(#1))}} % more efficient:
+\permanent\def\luaexpr#1{\ctxlua{tex.print(tostring(#1))}} % no use is shortcutting has to be compiled
+
+%D But as we only use write 16 we could as well do all in \LUA\ and ignore the rest.
+%D Okay, we still can do writes here but only when not blocked.
+
+\aliased\let\syst_write_execute\clf_execute % always {...}
+
+%D There is a probably rather useless \type {\expression} command that can mix \LUA\ numeric
+%D expressions with \TEX\ commands (for as far that makes sense) that works like this:
+%D
+%D \starttyping
+%D \mathchardef\foooo 1234
+%D \def \mymacro {123.45}
+%D \scratchdimen 123pt
+%D \scratchskip 123pt
+%D \scratchtoks {34}
+%D
+%D \testfeatureonce{10000}{\edef\foo{\expression
+%D round(
+%D 12.3 * \scratchdimen
+%D - (12.3 * \scratchskip) / 2
+%D + 2 ^ 3
+%D * (
+%D - sqrt(12)
+%D - 10pt
+%D - \foooo
+%D + \luatexversion
+%D - \mymacro
+%D + \scratchtoks
+%D + \the\scratchcounter
+%D + \number\scratchcounter
+%D )
+%D )
+%D \relax}}
+%D
+%D \expression string.format("\letterpercent f",\elapsedtime/50000) \relax
+%D \stoptyping
+%D
+%D The final \type {\relax} is mandate because we also accept spaces. Of course we
+%D could have avoided it by using outer parenthesis but this is cleaner anyway.
+%D
+%D The \LMTX\ version supports te \type {xmath} and \type {xcomplex} functions and
+%D therefore one can have expressions that don't work in \MKIV.
+
+% maybe: \let\texexpr\expression
+
+\protect \endinput