blob: 6ad8f5a991aeec4faf33fd6e5c1a400074d36d10 (
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
122
123
|
%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}{}
\unprotect
\def\expdoifelse#1#2{\clf_doifelsesame{#1}{#2}}
\def\expdoif #1#2{\clf_doifsame {#1}{#2}}
\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.
\def\expandeddoifelse#1#2%
{\immediateassignment\edef\m_syst_string_one{#1}%
\immediateassignment\edef\m_syst_string_two{#2}%
\ifx\m_syst_string_one\m_syst_string_two
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\def\expandeddoif#1#2%
{\immediateassignment\edef\m_syst_string_one{#1}%
\immediateassignment\edef\m_syst_string_two{#2}%
\ifx\m_syst_string_one\m_syst_string_two
\expandafter\firstofoneargument
\else
\expandafter\gobbleoneargument
\fi}
\def\expandeddoifnot#1#2%
{\immediateassignment\edef\m_syst_string_one{#1}%
\immediateassignment\edef\m_syst_string_two{#2}%
\ifx\m_syst_string_one\m_syst_string_two
\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
\def\expdoifelsecommon#1#2{\clf_doifelsecommon{#1}{#2}}
\def\expdoifelseinset #1#2{\clf_doifelseinset {#1}{#2}}
\def\expdoifcommonelse\expdoifelsecommon
\def\expdoifinsetelse \expdoifelseinset
%D We define these here, just in case. This permits \typefile {self} otherwise
%D nested b|/|e sep problems.
\def\luastringsep{===}
\edef\!!bs{[\luastringsep[}
\edef\!!es{]\luastringsep]}
\protected\def\writestatus#1#2{\clf_writestatus{#1}{#2}}
%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:
\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.
\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 \MKIV\ version is a bit more limited than the \LMTX\ version because it only
%D supports the standard math functions.
% maybe: \let\texexpr\expression
\protect \endinput
|