1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt File Macros Modules}
15
16\unprotect
17
18\registerctxluafile{filemod}{autosuffix}
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41\installcorenamespace{module}
42
43\mutable\let\currentmodule\s!unknown
44
45\mutable\lettonothing\currentmodulecategory
46\mutable\lettonothing\currentmoduleparameters
47
48\installmacrostack\currentmodule
49\installmacrostack\currentmodulecategory
50\installmacrostack\currentmoduleparameters
51
52\permanent\tolerant\protected\def\usemodules[#category]#spacer[#S#name]#spacer[#S#parameters]
53 {\push_macro_currentmodule
54 \push_macro_currentmodulecategory
55 \push_macro_currentmoduleparameters
56 \ifparameters
57 \lettonothing\currentmodule
58 \or
59 \lettonothing\currentmodulecategory
60 \cdef\currentmodule{#category}
61 \lettonothing\currentmoduleparameters
62 \or
63 \ifhastok={#name}
64 \lettonothing\currentmodulecategory
65 \cdef\currentmodule{#category}
66 \edef\currentmoduleparameters{#name}
67 \else
68 \edef\currentmodulecategory{#category}
69 \cdef\currentmodule{#name}
70 \lettonothing\currentmoduleparameters
71 \fi
72 \or
73 \edef\currentmodulecategory {#category}
74 \cdef\currentmodule {#name}
75 \def \currentmoduleparameters{#parameters}
76 \fi
77 \processcommacommand[\currentmodule]{\strc_modules_use\currentmodulecategory}
78 \pop_macro_currentmoduleparameters
79 \pop_macro_currentmodulecategory
80 \pop_macro_currentmodule}
81
82\def\strc_modules_use#category#name
83 {\ifempty\currentmoduleparameters\else
84 \scratchtoks\expandafter{\currentmoduleparameters}
85 \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}
86 \fi
87 \clf_usemodules{#category}{#name}}
88
89\aliased\let\usemodule \usemodules
90\aliased\let\usetexmodule\usemodules
91
92\newinteger\c_syst_modules_nesting
93\newtoks \everysetupmodule
94
95\permanent\tolerant\protected\def\startmodule[#1]#;#2
96 {\global\advanceby\c_syst_modules_nesting\plusone
97 \push_macro_currentmodule
98 \push_macro_currentmoduleparameters
99 \cdef\currentmodule{#1#2}}
100
101\permanent\protected\def\stopmodule
102 {\ifcase\c_syst_modules_nesting
103 \writestatus\m!system{module wrapping error in \currentmodule}
104 \else
105 \pop_macro_currentmoduleparameters
106 \pop_macro_currentmodule
107 \global\advanceby\c_syst_modules_nesting\minusone
108 \fi}
109
110\permanent\protected\def\setupmodule
111 {\ifempty\currentmoduleparameters
112 \expandafter\syst_modules_setup_nop
113 \else
114 \expandafter\syst_modules_setup_yes
115 \fi}
116
117\tolerant\def\syst_modules_setup_nop[#S#name]#spacer[#S#parameters]
118 {\ifarguments
119
120 \or
121 \ifhastok={#name}
122 \getparameters[\??module\currentmodule:][#name]
123 \fi
124 \or
125 \getparameters[\??module#name:][#parameters]
126 \fi
127 \expand\everysetupmodule}
128
129\tolerant\def\syst_modules_setup_yes[#S#name]#spacer[#S#parameters]
130 {\scratchtoks\expandafter{\currentmoduleparameters}
131 \ifparameters
132 \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}
133 \or
134 \ifhastok={#name}
135 \getparameters[\??module\currentmodule:][#name]
136 \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}
137 \else
138 \normalexpanded{\getparameters[\??module#1:][\the\scratchtoks]}
139 \fi
140 \or
141 \getparameters[\??module#name:][#parameters]
142 \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}
143 \fi
144 \lettonothing\currentmoduleparameters
145 \expand\everysetupmodule}
146
147\permanent\def\moduleparameter#name#parameter
148 {\begincsname\??module#name:#parameter\endcsname}
149
150\letvalue\??module\empty
151
152\permanent\def\currentmoduleparameter{\moduleparameter\currentmodule}
153
154
155
156\permanent\protected\def\useluamodule [#name]{\clf_useluamodule{#1}}
157\permanent\protected\def\luaenvironment #name {\clf_loadluamodule{#1}}
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178\permanent\protected\def\startmoduletestsection
179 {\begingroup
180 \setupmodule
181 \ifcstok{\currentmoduleparameter\v!test}\v!yes
182 \endgroup
183 \writestatus\currentmodule{loading experimental code}
184 \else
185 \endgroup
186 \writestatus\currentmodule{skipping experimental code}
187 \expandafter\ignoreupto\expandafter\stopmoduletestsection
188 \fi}
189
190\aliased\let\stopmoduletestsection\donothing
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208\permanent\protected\def\doifelseolderversion#parent#child{\clf_doifelseolderversion{#parent}{#child}}
209\permanent\protected\def\doifelseoldercontext #child{\clf_doifelseolderversion{#child}{}}
210
211\aliased\let\doifolderversionelse\doifelseolderversion
212\aliased\let\doifoldercontextelse\doifelseoldercontext
213
214
215
216\permanent\protected\def\syst_modules_direct_lua#1#2
217 {\edef\m_module_command_command {#1}
218 \edef\m_module_command_function{#2}
219 \directsetup{module:\m_module_command_command:start}
220 \ctxlua{\m_module_command_function()}
221 \directsetup{module:\m_module_command_command:stop}}
222
223\permanent\protected\def\syst_modules_single_lua#1#2
224 {\edef\m_module_command_command {#1}
225 \edef\m_module_command_function{#2}
226 \dosingleempty\syst_modules_single_lua_indeed}
227
228\permanent\protected\def\syst_modules_single_lua_indeed[#1]
229 {\directsetup{module:\m_module_command_command:start}
230 \ctxlua{\m_module_command_function(\!!bs#1\!!es)}
231 \directsetup{module:\m_module_command_command:stop}}
232
233\permanent\protected\def\syst_modules_double_lua#1#2
234 {\edef\m_module_command_command {#1}
235 \edef\m_module_command_function{#2}
236 \dodoubleempty\syst_modules_double_lua_indeed}
237
238\permanent\protected\def\syst_modules_double_lua_indeed[#1][#2]
239 {\directsetup{module:\m_module_command_command:start}
240 \ctxlua{\m_module_command_function(\!!bs#1\!!es,\!!bs#2\!!es)}
241 \directsetup{module:\m_module_command_command:stop}}
242
243\permanent\protected\def\installmodulecommandlua #1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_direct_lua{\csstring#1}{#2}}}}
244\permanent\protected\def\installmodulecommandluasingle#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_single_lua{\csstring#1}{#2}}}}
245\permanent\protected\def\installmodulecommandluadouble#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_double_lua{\csstring#1}{#2}}}}
246
247\protected\def\syst_modules_one_lua#1#2#3
248 {\directsetup{module:#1:start}
249 \ctxlua{#2(\!!bs#3\!!es)}
250 \directsetup{module:#1:stop}}
251
252\protected\def\syst_modules_two_lua#1#2#3#4
253 {\directsetup{module:#1:start}
254 \ctxlua{#2(\!!bs#3\!!es,\!!bs#4\!!es)}
255 \directsetup{module:#1:stop}}
256
257\permanent\protected\def\installmodulecommandluaone#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_one_lua{\csstring#1}{#2}}}}
258\permanent\protected\def\installmodulecommandluatwo#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_two_lua{\csstring#1}{#2}}}}
259
260
261
262
263
264
265
266\permanent\protected\def\fetchmodulecommand#1#2
267 {\mutable\protected\def#1{\syst_fetch_module_command#1{#2}}}
268
269\def\syst_fetch_module_command#1#2
270 {
271 \usemodule[#2]
272 #1}
273
274\aliased\let\fetchruntimecommand\fetchmodulecommand
275
276
277
278
279\protect \endinput
280 |