Debian Codegraph @

texmf-dist/source/luatex/lualibs/lualibs.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2009--2021 by
4 %
5 % PRAGMA ADE / ConTeXt Development Team
6 % The LaTeX Project Team
7 %
8 % See ConTeXt's mreadme.pdf for the license.
9 %
10 % This work consists of the main source file lualibs.dtx
11 % and the derived files lualibs.lua, lualibs-basic.lua,
12 % and lualibs-extended.lua.
13 %
14 % Unpacking:
15 % tex lualibs.dtx
16 %
17 % Documentation:
18 % lualatex lualibs.dtx
19 %
20 % The class ltxdoc loads the configuration file ltxdoc.cfg
21 % if available. Here you can specify further options, e.g.
22 % use A4 as paper format:
23 % \PassOptionsToClass{a4paper}{article}
24 %
25 %
26 %
27 %<*ignore>
28 \begingroup
29 \def\x{LaTeX2e}%
30 \expandafter\endgroup
31 \ifcase 0\ifx\install y1\fi\expandafter
32 \ifx\csname processbatchFile\endcsname\relax\else1\fi
33 \ifx\fmtname\x\else 1\fi\relax
34 \else\csname fi\endcsname
35 %</ignore>
36 %<*install>
37 \input docstrip.tex
38 \Msg{************************************************************************}
39 \Msg{* Installation}
40 \Msg{* Package: lualibs 2023-07-13 v2.76 Lua additional functions.}
41 \Msg{************************************************************************}
42
43 \keepsilent
44 \askforoverwritefalse
45
46 \let\MetaPrefix\relax
47
48 \preamble
49 This is a generated file.
50
51 Copyright (C) 2009--2021 by
52 PRAGMA ADE / ConTeXt Development Team
53 The LaTeX Project Team
54
55 See ConTeXt's mreadme.pdf for the license.
56
57 This work consists of the main source file lualibs.dtx
58 and the derived files lualibs.lua, lualibs-basic.lua,
59 and lualibs-extended.lua.
60
61 \endpreamble
62
63 % The following hacks are to generate a lua file with lua comments starting by
64 % -- instead of %%
65
66 \def\MetaPrefix{-- }
67
68 \def\luapostamble{%
69 \MetaPrefix^^J%
70 \MetaPrefix\space End of File `\outFileName'.%
71 }
72
73 \def\currentpostamble{\luapostamble}%
74
75 \generate{%
76 \usedir{tex/luatex/lualibs}%
77 \file{lualibs.lua}{\from{lualibs.dtx}{lualibs}}%
78 }
79
80 \generate{%
81 \usedir{tex/luatex/lualibs}%
82 \file{lualibs-basic.lua}{\from{lualibs.dtx}{basic}}%
83 }
84
85 \generate{%
86 \usedir{tex/luatex/lualibs}%
87 \file{lualibs-extended.lua}{\from{lualibs.dtx}{extended}}%
88 }
89
90 \obeyspaces
91 \Msg{************************************************************************}
92 \Msg{*}
93 \Msg{* To finish the installation you have to move the following}
94 \Msg{* files into a directory searched by TeX:}
95 \Msg{*}
96 \Msg{* lualibs.lua, lualibs-basic.lua, lualibs-extended.lua}
97 \Msg{*}
98 \Msg{* Happy TeXing!}
99 \Msg{*}
100 \Msg{************************************************************************}
101
102 \endbatchfile
103 %</install>
104 %<*ignore>
105 \fi
106 %</ignore>
107 %<*driver>
108 \NeedsTeXFormat{LaTeX2e}
109 \ProvidesFile{lualibs.drv}
110 [2023/07/13 v2.76 Lua Libraries.]
111 \documentclass{ltxdoc}
112 \usepackage{fancyvrb,xspace}
113 \usepackage[x11names]{xcolor}
114 %
115 \def\primarycolor{DodgerBlue4} %%-> rgb 16 78 139 | #104e8b
116 \def\secondarycolor{Goldenrod4} %%-> rgb 139 105 200 | #8b6914
117 %
118 \AddToHook{package/hyperref/after}{%
119 \hypersetup{
120 colorlinks=true,
121 linkcolor=\primarycolor,
122 urlcolor=\secondarycolor,
123 citecolor=\primarycolor,
124 pdftitle={The lualibs package},
125 pdfsubject={Port of the ConTeXt Lua libraries},
126 pdfauthor={Elie Roux & Philipp Gesang},
127 pdfkeywords={luatex, lualatex, unicode, opentype}}}
128
129 \newcommand*\email[1]{\href{mailto:#1}{#1}}
130 \usepackage{fontspec}
131 \setmainfont[
132 Numbers=OldStyle,
133 Ligatures=TeX,
134 ]{Linux Libertine O}
135 \setmonofont [Ligatures=TeX,Scale=MatchLowercase] {Liberation Mono}
136 \setsansfont [Ligatures=TeX,Scale=MatchLowercase] {Iwona Medium}
137 \usepackage{metalogo}
138 \EnableCrossrefs
139 \CodelineIndex
140 \newcommand\TEX {\TeX\xspace}
141 \newcommand\LATEX {\LaTeX\xspace}
142 \newcommand\LUA {Lua\xspace}
143 \newcommand\LUATEX {\LuaTeX\xspace}
144 \newcommand\CONTEXT {Con\TeX t\xspace}
145
146 \def\definehighlight[#1][#2]%
147 {\ifcsname #1\endcsname\else
148 \expandafter\def\csname #1\endcsname%
149 {\bgroup#2\csname #1_indeed\endcsname}
150 \expandafter\def\csname #1_indeed\endcsname##1%
151 {##1\egroup}%
152 \fi}
153
154 \def\restoreunderscore{\catcode`\_=12\relax}
155
156 \definehighlight [fileent][\ttfamily\restoreunderscore] %% files, dirs
157 \definehighlight [texmacro][\sffamily\itshape\textbackslash] %% cs
158 \definehighlight [luaident][\sffamily\itshape\restoreunderscore] %% lua identifiers
159 \definehighlight [identifier][\sffamily] %% names
160 \definehighlight [abbrev][\rmfamily\scshape] %% acronyms
161 \definehighlight [emphasis][\rmfamily\slshape] %% level 1 emph
162
163 \usepackage{titlesec}
164 \def\movecountertomargin#1{\llap{\rmfamily\upshape#1\hskip2em}}
165 \def\zeropoint{0pt}
166 %% we don’t have to grab attention like a child
167 \titleformat \part
168 {\normalsize\bfseries}
169 {\movecountertomargin\thepart} \zeropoint {}
170 \titleformat \section
171 {\normalsize\scshape}%% no \word; life is full of disappointments
172 {\movecountertomargin\thesection} \zeropoint {}
173 \titleformat \subsection
174 {\small\itshape}
175 {\movecountertomargin\thesubsection} \zeropoint {}
176 \renewcommand\partname{Part}%% gets rid of the stupid “file” heading
177
178 \usepackage{tocloft}
179 \renewcommand \cftpartfont {\rmfamily\upshape}
180 \renewcommand \cftsecfont {\rmfamily\upshape}
181 \renewcommand \cftsubsecfont {\rmfamily\upshape}
182 \setlength \cftbeforepartskip {1ex}
183 \setlength \cftbeforesecskip {1ex}
184
185 \begin{document}
186 \DocInput{lualibs.dtx}%
187 \end{document}
188 %</driver>
189 % \fi
190 % \CheckSum{0}
191 %
192 % \CharacterTable
193 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
194 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
195 % Digits \0\1\2\3\4\5\6\7\8\9
196 % Exclamation \! Double quote \" Hash (number) \#
197 % Dollar \$ Percent \% Ampersand \&
198 % Acute accent \' Left paren \( Right paren \)
199 % Asterisk \* Plus \+ Comma \,
200 % Minus \- Point \. Solidus \/
201 % Colon \: Semicolon \; Less than \<
202 % Equals \= Greater than \> Question mark \?
203 % Commercial at \@ Left bracket \[ Backslash \\
204 % Right bracket \] Circumflex \^ Underscore \_
205 % Grave accent \` Left brace \{ Vertical bar \|
206 % Right brace \} Tilde \~}
207 %
208 % \GetFileInfo{lualibs.drv}
209 %
210 % \title{The \identifier{lualibs} package}
211 % \date{2023/07/13 v2.76}
212 % \author{Élie Roux · \email{[email protected]}\\
213 % Philipp Gesang · \email{[email protected]}\\
214 % The \LaTeX{} Project · \email{https://github.com/latex3/lualibs/}\\
215 % }
216 %
217 % \maketitle
218 %
219 % \begin{abstract}
220 % Additional \LUA functions taken from the \verb|l-*| and \verb|util-*| files
221 % of \CONTEXT.
222 % For an introduction on this package (among others), please refer
223 % to the document \fileent{lualatex-doc.pdf}.
224 % \end{abstract}
225 %
226 % \tableofcontents
227 %
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % \part{Package Description}
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 % \section{Overview}
232 %
233 % \LUA is a very minimal language, and it does only have a minimal standard
234 % library. The aim of this package is to provide an extended standard library,
235 % to be used by various \LUATEX packages. The code is specific to \LUATEX
236 % and depends on \LUATEX functions and modules not available in regular lua.
237 %
238 % \noindent The code is derived from \CONTEXT libraries.
239 %
240 % \section{Usage}
241 %
242 % You can either load the \identifier{lualibs} module, which will in turn load
243 % one of two sets of libraries provided by this package: |require("lualibs")|, or
244 % explicitly load the modules you need, e.g.: |require("lualibs-table")|,
245 % please note that some modules depend on others.
246 %
247 % \subsection{Loading Library Collections}
248 %
249 % The libraries are split into a \identifier{basic} and an
250 % \identifier{extended} collection.
251 % Though neither initialization time nor memory consumption will be noticably
252 % impacted,\footnote{%
253 % Note that in terms of code this is only a small fraction of what
254 % \CONTEXT loads with every run.
255 % }
256 % the \identifier{lualibs} package can skip loading of the latter on demand.
257 % The \luaident{config} table needs to be present prior to loading the
258 % package for this to work (in the future this may be achieved by an option of
259 % \texmacro{usepackage}) for \LATEX users).
260 % In the \verb|lualibs| field, set \verb|load_extended| to false:
261 %
262 % \begin{quote}\begin{verbatim}
263 % \directlua{
264 % --- 1) create config table safely
265 % config = config or { }
266 % config.lualibs = config.lualibs or { }
267 %
268 % --- 2) unset the load_extended entry
269 % config.lualibs.load_extended = false
270 %
271 % --- 3) load the lualibs
272 % require "lualibs"
273 % }
274 % \end{verbatim}\end{quote}
275 %
276 % However, there is no guarantee that the \identifier{extended} set remains
277 % permanently excluded.
278 % Re-loading the package at a later point will cancel this option and possibly
279 % add the missing libraries.
280 %
281 % \subsection{Loading libraries Individually}
282 % In order to load the \fileent{table} module you would actually have to prepare
283 % it as follows:
284 %
285 % \begin{quote}\begin{verbatim}
286 % require"lualibs-lua"
287 % require"lualibs-lpeg"
288 % require"lualibs-table"
289 % \end{verbatim}\end{quote}
290 %
291 % \noindent
292 % If your code is run by the \fileent{texlua} intepreter, you will need to
293 % initialize \luaident{kpse} library so that |require()| can find files
294 % under \abbrev{texmf} tree: |kpse.set_program_name("luatex")|.
295 %
296 % \section{Files}
297 %
298 % The \identifier{lualibs} bundle contains files from two \CONTEXT \LUA
299 % library categories: The generic auxiliary functions (original file prefix:
300 % |l-|) together form something close to a standard libary. Most of these are
301 % extensions of an existing namespace, like for instance |l-table.lua| which
302 % adds full-fledged serialization capabilities to the \LUA table library.
303 % They were imported under the \identifier{lualibs}-prefix and are contained
304 % in the \identifier{basic} collection.
305 % (For a list see table~\ref{tab:basic}.)
306 %
307 % \begin{table}[t]
308 % \hrule
309 % \centering
310 % \caption{The \identifier{basic} set.}
311 % \vskip1em
312 % \begin{tabular}{l l l}
313 % \identifier{lualibs} name & \CONTEXT name & primary purpose \\[1ex]
314 % lualibs-lua.lua & l-lua.lua & compatibility \\
315 % lualibs-package.lua & l-package.lua & \LUA file loaders \\
316 % lualibs-lpeg.lua & l-lpeg.lua & patterns \\
317 % lualibs-function.lua & l-function.lua & defines a dummy function \\
318 % lualibs-string.lua & l-string.lua & string manipulation \\
319 % lualibs-table.lua & l-table.lua & serialization, conversion \\
320 % lualibs-boolean.lua & l-boolean.lua & boolean converter \\
321 % lualibs-number.lua & l-number.lua & bit operations \\
322 % lualibs-math.lua & l-math.lua & math functions \\
323 % lualibs-io.lua & l-io.lua & reading and writing files \\
324 % lualibs-os.lua & l-os.lua & platform specific code \\
325 % lualibs-file.lua & l-file.lua & filesystem operations \\
326 % lualibs-md5.lua & l-md5.lua & checksum functions \\
327 % lualibs-dir.lua & l-dir.lua & directory handling \\
328 % lualibs-unicode.lua & l-unicode.lua & utf and unicode \\
329 % lualibs-url.lua & l-url.lua & url handling \\
330 % lualibs-set.lua & l-set.lua & sets \\
331 % \end{tabular}
332 % \label{tab:basic}
333 % \hrule
334 % \end{table}
335 %
336 % The \identifier{extended} category comprises a selection of files mostly from
337 % the utilities namespace (|util-|; cf. table~\ref{tab:extended}).
338 % Their purpose is more specific and at times quite low-level.
339 % Additionally, the file \fileent{trac-inf.lua} has been included because it is
340 % essential to some of the code loaded subsequently.
341 %
342 % \begin{table}[t]
343 % \hrule
344 % \centering
345 % \caption{The \identifier{extended} set.}
346 % \vskip1em
347 % \begin{tabular}{l l l}
348 % \identifier{lualibs} name & \CONTEXT name & primary purpose \\[1ex]
349 % lualibs-util-sac.lua & util-sac.lua & string based file readers \\
350 % lualibs-util-str.lua & util-str.lua & extra |string| functions \\
351 % lualibs-util-fil.lua & util-fil.lua & extra |file| functions \\
352 % lualibs-util-tab.lua & util-tab.lua & extra |table| functions \\
353 % lualibs-util-sto.lua & util-sto.lua & table allocation \\
354 % lualibs-util-prs.lua & util-sto.lua & miscellaneous parsers \\
355 % lualibs-util-dim.lua & util-dim.lua & conversion between dimensions \\
356 % lualibs-trac-inf.lua & trac-inf.lua & timing, statistics \\
357 % lualibs-util-lua.lua & util-lua.lua & operations on bytecode \\
358 % lualibs-util-deb.lua & util-deb.lua & extra |debug| functionality \\
359 % lualibs-util-tpl.lua & util-tpl.lua & templating \\
360 % lualibs-util-sta.lua & util-sta.lua & stacker (e.~g. for \abbrev{pdf}) \\
361 % lualibs-util-jsn.lua & util-jsn.lua & conversion to and from json \\
362 % lualibs-util-zip.lua & util-zip.lua & compression and zip files \\[1ex]
363 % \end{tabular}
364 % \label{tab:extended}
365 % \hrule
366 % \end{table}
367 %
368 % \section{Packaging}
369 %
370 % By default, \identifier{lualibs} will not load the libraries individually.
371 % Instead, it includes two \emphasis{merged packages} that have been compiled
372 % from the original files.
373 % This is achieved by means of \identifier{mtx-package}, a script for bundling
374 % \LUA code shipped with \CONTEXT.
375 % This concatenates the code of several \LUA files into a single file that is
376 % both easier to distribute and loading marginally faster.
377 % \identifier{mtx-package} ensures that the code from each file gets its
378 % own closure and strips newlines and comments, resulting in a smaller payload.
379 % Another package that relies on it heavily is the font loader as contained in
380 % \identifier{luaotfload} and \identifier{luatex-fonts}.
381 % \identifier{Luaotfload}, a port of the \CONTEXT fontloader for Plain and
382 % \LATEX, has a hard dependency on the functionality provided by the %
383 % \identifier{Lualibs} package. The packages should not be updated independently.
384 %
385 % If \CONTEXT is installed on the system, the merge files can be created
386 % by running:
387 %
388 % \begin{quote}\begin{verbatim}
389 % mtxrun --script package --merge lualibs-basic.lua
390 % mtxrun --script package --merge lualibs-extended.lua
391 % \end{verbatim}\end{quote}
392 %
393 % \noindent
394 % Of course there is a make target for that:
395 %
396 % \begin{quote}\begin{verbatim}
397 % make merge
398 % \end{verbatim}\end{quote}
399 % \noindent
400 % will take care of assembling the packages from the files distributed with
401 % \identifier{lualibs}.
402 %
403 % For this to work, the syntax of the \LUA file needs to be well-formed:
404 % files that should be merged must be included via a function
405 % \verb|loadmodule()|.
406 % It doesn’t matter if the function actually does something; a dummy will
407 % suffice.
408 % Also, the argument to \verb|loadmodule()| must be wrapped in parentheses.
409 % This rule is quite convenient, actually, since it allows excluding files
410 % from the merge while still using \verb|loadmodule()| consistently.
411 %
412 % \begin{quote}\begin{verbatim}
413 % ...
414 % loadmodule("my-lua-file.lua") -- <= will be merged
415 % loadmodule('my-2nd-file.lua') -- <= will be merged
416 % loadmodule "my-3rd-file.lua" -- <= will be ignored
417 % ...
418 % \end{verbatim}\end{quote}
419 %
420 %
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 % \part{\texorpdfstring{\fileent{lualibs.lua}}{lualibs.lua}}
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 %
425 % \iffalse
426 %<*lualibs>
427 % \fi
428 % \begin{macrocode}
429 lualibs = lualibs or { }
430
431 lualibs.module_info = {
432 name = "lualibs",
433 version = "2.76", --TAGVERSION
434 date = "2023-07-13", --TAGDATE
435 description = "ConTeXt Lua standard libraries.",
436 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
437 copyright = "PRAGMA ADE / ConTeXt Development Team",
438 license = "See ConTeXt's mreadme.pdf for the license",
439 }
440
441 % \end{macrocode}
442 % The behavior of the lualibs can be configured to some extent.
443 % \begin{itemize}
444 % \item Based on the parameter \verb|lualibs.prefer_merged|, the
445 % libraries can be loaded via the included merged packages or
446 % the individual files.
447 % \item Two classes of libraries are distinguished, mainly because
448 % of a similar distinction in \CONTEXT, but also to make
449 % loading of the less fundamental functionality optional.
450 % While the “basic” collection is always loaded, the
451 % configuration setting \verb|lualibs.load_extended| triggers
452 % inclusion of the extended collection.
453 % \item Verbosity can be increased via the \verb|verbose| switch.
454 % \end{itemize}
455 %
456 % \begin{macrocode}
457
458 config = config or { }
459 config.lualibs = config.lualibs or { }
460
461 if config.lualibs.prefer_merged ~= nil then
462 lualibs.prefer_merged = config.lualibs.prefer_merged
463 else
464 lualibs.prefer_merged = true
465 end
466
467 if config.lualibs.load_extended ~= nil then
468 lualibs.load_extended = config.lualibs.load_extended
469 else
470 lualibs.load_extended = true
471 end
472
473 if config.lualibs.verbose ~= nil then
474 config.lualibs.verbose = config.lualibs.verbose
475 else
476 config.lualibs.verbose = false
477 end
478
479 % \end{macrocode}
480 % The lualibs may be loaded in scripts.
481 % To account for the different environment, fallbacks for
482 % the luatexbase facilities are installed.
483 %
484 % \begin{macrocode}
485
486 local dofile = dofile
487 local kpsefind_file = kpse.find_file
488 local stringformat = string.format
489 local texiowrite_nl = texio.write_nl
490
491 local find_file, error, warn, info
492 do
493 local _error, _warn, _info
494 if luatexbase and luatexbase.provides_module then
495 _error, _warn, _info = luatexbase.provides_module(lualibs.module_info)
496 else
497 _error, _warn, _info = texiowrite_nl, texiowrite_nl, texiowrite_nl
498 end
499
500 if lualibs.verbose then
501 error, warn, info = _error, _warn, _info
502 else
503 local dummylogger = function ( ) end
504 error, warn, info = _error, dummylogger, dummylogger
505 end
506 lualibs.error, lualibs.warn, lualibs.info = error, warn, info
507 end
508
509 if status.kpse_used == 0 then
510 kpse.set_program_name("luatex")
511 end
512
513 find_file = kpsefind_file
514
515 % \end{macrocode}
516 % The lualibs load a merged package by default.
517 % In order to create one of these, the meta file that includes the
518 % libraries must satisfy certain assumptions \verb|mtx-package| makes
519 % about the coding style.
520 % Most important is that the functions that indicates which files
521 % to include must go by the name \verb|loadmodule()|.
522 % For this reason we define a \verb|loadmodule()| function as a
523 % wrapper around \verb|dofile()|.
524 %
525 % \begin{macrocode}
526
527 local loadmodule = loadmodule or function (name, t)
528 if not t then t = "library" end
529 local filepath = find_file(name, "lua")
530 if not filepath or filepath == "" then
531 warn(stringformat("Could not locate %s “%s”.", t, name))
532 return false
533 end
534 dofile(filepath)
535 return true
536 end
537
538 lualibs.loadmodule = loadmodule
539
540 % \end{macrocode}
541 % The separation of the “basic” from the “extended” sets coincides
542 % with the split into luat-bas.mkiv and luat-lib.mkiv.
543 %
544 % \begin{macrocode}
545
546 if lualibs.basic_loaded ~= true
547 or config.lualibs.force_reload == true
548 then
549 loadmodule"lualibs-basic.lua"
550 loadmodule"lualibs-compat.lua" --- restore stuff gone since v1.*
551 end
552
553 if lualibs.load_extended == true
554 and lualibs.extended_loaded ~= true
555 or config.lualibs.force_reload == true
556 then
557 loadmodule"lualibs-extended.lua"
558 end
559
560 --- This restores the default of loading everything should a package
561 --- have requested otherwise. Will be gone once there is a canonical
562 --- interface for parameterized loading of libraries.
563 config.lualibs.load_extended = true
564
565 -- vim:tw=71:sw=2:ts=2:expandtab
566
567 % \end{macrocode}
568 %
569 % \iffalse
570 %</lualibs>
571 % \fi
572 %
573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574 % \part{\texorpdfstring{\fileent{lualibs-basic.lua}}{lualibs-basic.lua}}
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 %
577 % \iffalse
578 %<*basic>
579 % \fi
580 % \begin{macrocode}
581 lualibs = lualibs or { }
582 local info = lualibs.info
583 local loadmodule = lualibs.loadmodule
584
585 local lualibs_basic_module = {
586 name = "lualibs-basic",
587 version = "2.76", --TAGVERSION
588 date = "2023-07-13", --TAGDATE
589 description = "ConTeXt Lua libraries -- basic collection.",
590 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
591 copyright = "PRAGMA ADE / ConTeXt Development Team",
592 license = "See ConTeXt's mreadme.pdf for the license",
593 }
594
595 local loaded = false --- track success of package loading
596
597 if lualibs.prefer_merged then
598 info"Loading merged package for collection “basic”."
599 loaded = loadmodule('lualibs-basic-merged.lua')
600 else
601 info"Ignoring merged packages."
602 info"Falling back to individual libraries from collection “basic”."
603 end
604
605 % \end{macrocode}
606 % \verb|mtx-package| expects the files to be included by
607 % \verb|loadmodule|.
608 % If run on this file, it will create \verb|lualibs-basic-merged.lua|
609 % from all the files mentioned in the next block.
610 %
611 % \begin{macrocode}
612
613 if loaded == false then
614 loadmodule("lualibs-lua.lua")
615 loadmodule("lualibs-package.lua")
616 loadmodule("lualibs-lpeg.lua")
617 loadmodule("lualibs-function.lua")
618 loadmodule("lualibs-string.lua")
619 loadmodule("lualibs-table.lua")
620 loadmodule("lualibs-boolean.lua")
621 loadmodule("lualibs-number.lua")
622 loadmodule("lualibs-math.lua")
623 loadmodule("lualibs-io.lua")
624 loadmodule("lualibs-os.lua")
625 loadmodule("lualibs-file.lua")
626 loadmodule("lualibs-md5.lua")
627 loadmodule("lualibs-dir.lua")
628 loadmodule("lualibs-unicode.lua")
629 loadmodule("lualibs-url.lua")
630 loadmodule("lualibs-set.lua")
631 end
632
633 lualibs.basic_loaded = true
634 -- vim:tw=71:sw=2:ts=2:expandtab
635
636 % \end{macrocode}
637 %
638 % \iffalse
639 %</basic>
640 % \fi
641 %
642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
643 % \part{\texorpdfstring{\fileent{lualibs-extended.lua}}{lualibs-extended.lua}}
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
645 %
646 % \iffalse
647 %<*extended>
648 % \fi
649 % \begin{macrocode}
650 lualibs = lualibs or { }
651
652 % \end{macrocode}
653 % Loading the \emph{extended} set requires a tad more effort, but
654 % it’s well invested.
655 %
656 % Since we only want the functionality, we have to simulate parts
657 % of a running \CONTEXT environment, above all logging, that some
658 % of the more involved libraries cannot be loaded without.
659 % Also, one utility file cannot be packaged because it returns a
660 % table which would preclude loading of later code.
661 % Thus, we remove it from the natural loading chain (it is not
662 % critical) and append it at the end.
663 %
664 % \begin{macrocode}
665
666 local lualibs_extended_module = {
667 name = "lualibs-extended",
668 version = "2.76", --TAGVERSION
669 date = "2023-07-13", --TAGDATE
670 description = "ConTeXt Lua libraries -- extended collection.",
671 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
672 copyright = "PRAGMA ADE / ConTeXt Development Team",
673 license = "See ConTeXt's mreadme.pdf for the license",
674 }
675
676
677 local stringformat = string.format
678 local loadmodule = lualibs.loadmodule
679 local texiowrite = texio.write
680 local texiowrite_nl = texio.write_nl
681
682 % \end{macrocode}
683 % Here we define some functions that fake the elaborate
684 % logging/tracking mechanism Context provides.
685 %
686 % \begin{macrocode}
687
688 local error, logger, mklog
689 if luatexbase and luatexbase.provides_module then
690 --- TODO test how those work out when running tex
691 local __error,_,_,__logger =
692 luatexbase.provides_module(lualibs_extended_module)
693 error = __error
694 logger = __logger
695 mklog = function ( ) return logger end
696 else
697 mklog = function (t)
698 local prefix = stringformat("[%s] ", t)
699 return function (...)
700 texiowrite_nl(prefix)
701 texiowrite (stringformat(...))
702 end
703 end
704 error = mklog"ERROR"
705 logger = mklog"INFO"
706 end
707
708 local info = lualibs.info
709
710 % \end{macrocode}
711 % We temporarily put our own global table in place and restore
712 % whatever we overloaded afterwards.
713 %
714 % \CONTEXT\ modules each have a custom logging mechanism that can be
715 % enabled for debugging.
716 % In order to fake the presence of this facility we need to define at
717 % least the function \verb|logs.reporter|.
718 % For now it’s sufficient to make it a reference to \verb|mklog| as
719 % defined above.
720 %
721 % \begin{macrocode}
722
723 local dummy_function = function ( ) end
724 local newline = function ( ) texiowrite_nl"" end
725
726 local fake_logs = function (name)
727 return {
728 name = name,
729 enable = dummy_function,
730 disable = dummy_function,
731 reporter = mklog,
732 newline = newline
733 }
734 end
735
736 local fake_trackers = function (name)
737 return {
738 name = name,
739 enable = dummy_function,
740 disable = dummy_function,
741 register = mklog,
742 newline = newline,
743 }
744 end
745
746 local backup_store = { }
747
748 local fake_context = function ( )
749 if logs then backup_store.logs = logs end
750 if trackers then backup_store.trackers = trackers end
751 logs = fake_logs"logs"
752 trackers = fake_trackers"trackers"
753 end
754
755
756 % \end{macrocode}
757 % Restore a backed up logger if appropriate.
758 %
759 % \begin{macrocode}
760 local unfake_context = function ( )
761 if backup_store then
762 local bl, bt = backup_store.logs, backup_store.trackers
763 if bl then logs = bl end
764 if bt then trackers = bt end
765 end
766 end
767
768 fake_context()
769
770 local loaded = false
771 if lualibs.prefer_merged then
772 info"Loading merged package for collection “extended”."
773 loaded = loadmodule('lualibs-extended-merged.lua')
774 else
775 info"Ignoring merged packages."
776 info"Falling back to individual libraries from collection “extended”."
777 end
778
779 if loaded == false then
780 loadmodule("lualibs-util-sac.lua")--- streams: string based file parsers
781 loadmodule("lualibs-util-str.lua")--- string formatters (fast)
782 loadmodule("lualibs-util-fil.lua")--- extra file helpers
783 loadmodule("lualibs-util-tab.lua")--- extended table operations
784 loadmodule("lualibs-util-sto.lua")--- storage (hash allocation)
785 ----------("lualibs-util-pck.lua")---!packers; necessary?
786 ----------("lualibs-util-seq.lua")---!sequencers (function chaining)
787 ----------("lualibs-util-mrg.lua")---!only relevant in mtx-package
788 loadmodule("lualibs-util-prs.lua")--- miscellaneous parsers; cool. cool cool cool
789 ----------("lualibs-util-fmt.lua")---!column formatter (rarely used)
790 loadmodule("lualibs-util-dim.lua")--- conversions between dimensions
791 loadmodule("lualibs-util-jsn.lua")--- JSON parser
792
793 ----------("lualibs-trac-set.lua")---!generalization of trackers
794 ----------("lualibs-trac-log.lua")---!logging
795 loadmodule("lualibs-trac-inf.lua")--- timing/statistics
796 loadmodule("lualibs-util-lua.lua")--- operations on lua bytecode
797 loadmodule("lualibs-util-deb.lua")--- extra debugging
798 loadmodule("lualibs-util-tpl.lua")--- templating
799 loadmodule("lualibs-util-sta.lua")--- stacker (for writing pdf)
800 loadmodule("lualibs-util-zip.lua")--- compression and zip files
801 end
802
803 unfake_context() --- TODO check if this works at runtime
804
805 lualibs.extended_loaded = true
806 -- vim:tw=71:sw=2:ts=2:expandtab
807
808 % \end{macrocode}
809 %
810 % \iffalse
811 %</extended>
812 % \fi
813 %
814 % \Finale
815 \endinput