luat-cod.mkiv /size: 2655 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=luat-cod,
3%D        version=2005.05.26,
4%D          title=\CONTEXT\ Lua Macros,
5%D       subtitle=Code,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% \writestatus{loading}{ConTeXt Lua Macros / Code}
15
16\unprotect
17
18%D We cannot use the following due to the fact that existing usage demanded
19%D duplicating hashes.
20%D
21%D \starttyping
22%D \def\expanded#1{\normalexpanded{\noexpand#1}} % ## mess
23%D \stoptyping
24
25\newif\ifproductionrun
26
27%D Originally we compiled the \LUA\ files externally and loaded then at runtime, but
28%D when the amount grew, we realized that we needed away to store them in the
29%D format, which is what bytecode arrays do. And so the following is obsolete:
30%D
31%D \starttyping
32%D \setnewconstant\ctxluaembeddingmode \plusone
33%D
34%D 0 = external compilation and loading
35%D 1 = runtime compilation and embedding
36%D \stoptyping
37%D
38%D Allocation of \LUA\ engines has changed too. The original idea was to have
39%D multiple \LUA\ instances and it worked that way for several years. Hoewver in
40%D practice we used only one engine because scripts need to share data anyway. So
41%D eventually \LUATEX\ got only one instance. Because each call is reentrant there
42%D is not much danger for crashes.
43%D
44%D Most code here has changed after version 0.60 as part of adaption to new
45%D functionality. We no longer support the hooks for initializing code as this can
46%D be done at the \LUA\ end.
47
48% we can drop the \zerocount as it's default
49
50\let\ctxdirectlua       \directlua
51\let\ctxlatelua         \latelua
52\def\ctxsprint       #1{\directlua{tex.sprint(tex.ctxcatcodes,#1)}} % saves tokens
53\def\ctxwrite        #1{\directlua{tex.write(#1)}} % saves tokens
54\def\ctxcommand      #1{\directlua{commands.#1}} % saves tokens
55\def\ctxdirectcommand#1{\directlua{commands.#1}} % saves tokens
56\def\ctxlatecommand  #1{\latelua  {commands.#1}} % saves tokens
57\def\ctxreport       #1{\directlua{logs.writer[[#1]]}}
58
59%D Take your choice \unknown
60
61\let\ctxlua       \ctxdirectlua
62\let\luacode      \ctxdirectlua
63\let\lateluacode  \ctxlatelua
64\let\directluacode\ctxdirectlua
65
66%D Reporting the version of \LUA\ that we use is done as follows:
67
68\def\luaversion{\ctxwrite{LUAVERSION}}
69
70\def\registerctxluafile#1#2{\ctxlua{lua.registercode("#1","#2")}}
71\def\ctxloadluafile      #1{\ctxlua{lua.registercode("#1")}}
72
73\registerctxluafile{luat-cod}{}
74
75% \everydump\expandafter{\the\everydump\ctxlua{lua.finalize()}}
76
77\protect \endinput
78