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}{}
19
20
21
22
23
24
25
26
27
28
29
30
31
32\unexpanded\def\usemodules
33 {\dotripleempty\strc_modules_use}
34
35\let\usemodule \usemodules
36\let\usetexmodule\usemodules
37
38\def\strc_modules_use[#category][#name][#parameters]
39 {\push_macro_currentmodule
40 \push_macro_currentmodulecategory
41 \push_macro_currentmoduleparameters
42 \ifthirdargument
43 \edef\currentmodulecategory {#category}
44 \edef\currentmodule {#name}
45 \def \currentmoduleparameters{#parameters}
46 \else\ifsecondargument
47 \doifelseassignment{#name}
48 {\let\currentmodulecategory \empty
49 \edef\currentmodule {#category}
50 \edef\currentmoduleparameters{#name}}
51 {\edef\currentmodulecategory {#category}
52 \edef\currentmodule {#name}
53 \let \currentmoduleparameters\empty}
54 \else
55 \let \currentmodulecategory \empty
56 \edef\currentmodule {#category}
57 \let \currentmoduleparameters\empty
58 \fi\fi
59 \processcommacommand[\currentmodule]{\strc_modules_use_indeed\currentmodulecategory}
60 \pop_macro_currentmoduleparameters
61 \pop_macro_currentmodulecategory
62 \pop_macro_currentmodule}
63
64\def\strc_modules_use_indeed#category#name
65 {\ifx\currentmoduleparameters\empty\else
66 \scratchtoks\expandafter{\currentmoduleparameters}
67 \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}
68 \fi
69 \clf_usemodules{#category}{#name}}
70
71\installcorenamespace{module}
72
73\let\currentmodule \s!unknown
74\let\currentmodulecategory \empty
75\let\currentmoduleparameters\empty
76
77\installmacrostack\currentmodule
78\installmacrostack\currentmodulecategory
79\installmacrostack\currentmoduleparameters
80
81\newcount\c_syst_modules_nesting
82\newtoks \everysetupmodule
83
84\unexpanded\def\startmodule
85 {\doifelsenextoptionalcs\syst_modules_start_yes\syst_modules_start_nop}
86
87\def\syst_modules_start_yes[#name]
88 {\global\advance\c_syst_modules_nesting\plusone
89 \push_macro_currentmodule
90 \push_macro_currentmoduleparameters
91 \def\currentmodule{#name}}
92
93\def\syst_modules_start_nop#name
94 {\syst_modules_start_yes[#name]}
95
96\unexpanded\def\stopmodule
97 {\ifcase\c_syst_modules_nesting
98 \writestatus\m!system{module wrapping error in \currentmodule}
99 \else
100 \pop_macro_currentmoduleparameters
101 \pop_macro_currentmodule
102 \global\advance\c_syst_modules_nesting\minusone
103 \fi}
104
105\unexpanded\def\setupmodule
106 {\dodoubleempty\syst_modules_setup}
107
108\def\syst_modules_setup
109 {\ifx\currentmoduleparameters\empty
110 \expandafter\syst_modules_setup_nop
111 \else
112 \expandafter\syst_modules_setup_yes
113 \fi}
114
115\def\syst_modules_setup_nop[#name][#parameters]
116 {\ifsecondargument
117 \getparameters[\??module#name:][#parameters]
118 \else\iffirstargument
119 \doifassignmentelse{#name}{\getparameters[\??module\currentmodule:][#name]}\donothing
120 \fi\fi
121 \the\everysetupmodule}
122
123\def\syst_modules_setup_yes[#name][#parameters]
124 {\scratchtoks\expandafter{\currentmoduleparameters}
125 \ifsecondargument
126 \getparameters[\??module#name:][#parameters]
127 \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}
128 \else\iffirstargument
129 \doifassignmentelse{#name}
130 {\getparameters[\??module\currentmodule:][#name]
131 \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}}
132 {\normalexpanded{\getparameters[\??module#1:][\the\scratchtoks]}}
133 \else
134 \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}
135 \fi\fi
136 \let\currentmoduleparameters\empty
137 \the\everysetupmodule}
138
139
140
141
142
143
144
145
146
147
148
149
150
151\def\moduleparameter#name#parameter
152 {\begincsname\??module#name:#parameter\endcsname}
153
154\letvalue\??module\empty
155
156\def\currentmoduleparameter{\moduleparameter\currentmodule}
157
158\unexpanded\def\useluamodule [#name]{\clf_loadluamodule{#1}}
159\unexpanded\def\luaenvironment #name {\clf_loadluamodule{#1}}
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180\unexpanded\def\startmoduletestsection
181 {\begingroup
182 \setupmodule
183 \doifelse{\currentmoduleparameter\v!test}\v!yes
184 {\endgroup
185 \writestatus\currentmodule{loading experimental code}}
186 {\endgroup
187 \writestatus\currentmodule{skipping experimental code}
188 \gobbleuntil\stopmoduletestsection}}
189
190\let\stopmoduletestsection\donothing
191
192
193
194
195
196
197
198
199
200
201\installcorenamespace{runtimeloaded}
202
203\unexpanded\def\fetchruntimecommand#1#2
204 {\unexpanded\def#1{\dofetchruntimecommand#1{#2}}}
205
206\def\dofetchruntimecommand#1#2
207 {\ifcsname\??runtimeloaded#2\endcsname
208
209 \else
210 \glet#1\undefined
211 \startreadingfile
212 \startnointerference
213 \cleanupfeatures
214 \readfile{#2.\mksuffix}\donothing\donothing
215 \stopnointerference
216 \stopreadingfile
217 \letgvalue{\??runtimeloaded#2}\empty
218 \fi
219 \ifx#1\undefined
220 \writestatus\m!system{command \string#1 not found in file #2}
221 \unexpanded\gdef#1{{\infofont[unknown command \string#1]}}
222 \fi
223 #1}
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239\unexpanded\def\doifelseolderversion#parent#child{\clf_doifelseolderversion{#parent}{#child}}
240\unexpanded\def\doifelseoldercontext #child{\clf_doifelseolderversion{#child}{}}
241
242\let\doifolderversionelse\doifelseolderversion
243\let\doifoldercontextelse\doifelseoldercontext
244
245
246
247\unexpanded\def\syst_modules_direct_lua#1#2
248 {\edef\m_module_command_command {#1}
249 \edef\m_module_command_function{#2}
250 \directsetup{module:\m_module_command_command:start}
251 \ctxlua{\m_module_command_function()}
252 \directsetup{module:\m_module_command_command:stop}}
253
254\unexpanded\def\syst_modules_single_lua#1#2
255 {\edef\m_module_command_command {#1}
256 \edef\m_module_command_function{#2}
257 \dosingleempty\syst_modules_single_lua_indeed}
258
259\unexpanded\def\syst_modules_single_lua_indeed[#1]
260 {\directsetup{module:\m_module_command_command:start}
261 \ctxlua{\m_module_command_function(\!!bs#1\!!es)}
262 \directsetup{module:\m_module_command_command:stop}}
263
264\unexpanded\def\syst_modules_double_lua#1#2
265 {\edef\m_module_command_command {#1}
266 \edef\m_module_command_function{#2}
267 \dodoubleempty\syst_modules_double_lua_indeed}
268
269\unexpanded\def\syst_modules_double_lua_indeed[#1][#2]
270 {\directsetup{module:\m_module_command_command:start}
271 \ctxlua{\m_module_command_function(\!!bs#1\!!es,\!!bs#2\!!es)}
272 \directsetup{module:\m_module_command_command:stop}}
273
274\def\installmodulecommandlua #1#2{\unexpanded\def#1{\normalexpanded{\syst_modules_direct_lua{\strippedcsname#1}{#2}}}}
275\def\installmodulecommandluasingle#1#2{\unexpanded\def#1{\normalexpanded{\syst_modules_single_lua{\strippedcsname#1}{#2}}}}
276\def\installmodulecommandluadouble#1#2{\unexpanded\def#1{\normalexpanded{\syst_modules_double_lua{\strippedcsname#1}{#2}}}}
277
278\unexpanded\def\syst_modules_one_lua#1#2#3
279 {\directsetup{module:#1:start}
280 \ctxlua{#2(\!!bs#3\!!es)}
281 \directsetup{module:#1:stop}}
282
283\unexpanded\def\syst_modules_two_lua#1#2#3#4
284 {\directsetup{module:#1:start}
285 \ctxlua{#2(\!!bs#3\!!es,\!!bs#4\!!es)}
286 \directsetup{module:#1:stop}}
287
288\def\installmodulecommandluaone#1#2{\unexpanded\def#1{\normalexpanded{\syst_modules_one_lua{\strippedcsname#1}{#2}}}}
289\def\installmodulecommandluatwo#1#2{\unexpanded\def#1{\normalexpanded{\syst_modules_two_lua{\strippedcsname#1}{#2}}}}
290
291
292
293
294
295
296
297
298
299
300
301
302
303\unexpanded\def\useluamodule[#1]{\clf_useluamodule{#1}}
304
305\protect \endinput
306 |