summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/luat-cod.mkiv
blob: 9ce6161c32c9b740c45e7f511daadb99c5bcfb6b (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
%D \module
%D   [       file=luat-cod,
%D        version=2005.05.26,
%D          title=\CONTEXT\ Lua Macros,
%D       subtitle=Code,
%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.

% \writestatus{loading}{ConTeXt Lua Macros / Code}

\unprotect

%D We cannot use the following due to the fact that existing usage
%D demanded duplicating hashes.
%D
%D \starttyping
%D \def\expanded#1{\normalexpanded{\noexpand#1}} % ## mess
%D \stoptyping

\newif\ifproductionrun

%D Originally we compiled the \LUA\ files externally and loaded
%D then at runtime, but when the amount grew, we realized that
%D we needed away to store them in the format, which is what
%D bytecode arrays do. And so the following is obsolete:
%D
%D \starttyping
%D \setnewconstant\ctxluaembeddingmode \plusone
%D
%D 0 = external compilation and loading
%D 1 = runtime compilation and embedding
%D \stoptyping
%D
%D Allocation of \LUA\ engines has changed too. The original idea
%D was to have multiple \LUA\ instances and it worked that way for
%D several years. Hoewver in practice we used only one engine because
%D scripts need to share data anyway. So eventually \LUATEX\ got only
%D one instance. Because each call is reentrant there is not much
%D danger for crashes.
%D
%D Most code here has changed after version 0.60 as part of adaption to
%D new functionality. We no longer support the hooks for initializing
%D code as this can be done at the \LUA\ end.

% we can drop the \zerocount as it's default

\let\ctxdirectlua       \directlua
\let\ctxlatelua         \latelua
\def\ctxsprint       #1{\directlua{tex.sprint(tex.ctxcatcodes,#1)}} % saves tokens
\def\ctxwrite        #1{\directlua{tex.write(#1)}} % saves tokens
\def\ctxcommand      #1{\directlua{commands.#1}} % saves tokens
\def\ctxdirectcommand#1{\directlua{commands.#1}} % saves tokens
\def\ctxlatecommand  #1{\latelua  {commands.#1}} % saves tokens
\def\ctxreport       #1{\directlua{logs.writer[[#1]]}}

%D Take your choice \unknown

\let\ctxlua       \ctxdirectlua
\let\luacode      \ctxdirectlua
\let\lateluacode  \ctxlatelua
\let\directluacode\ctxdirectlua

%D Reporting the version of \LUA\ that we use is done as follows:

\edef\luaversion{\ctxwrite{_VERSION}}

\def\registerctxluafile#1#2{\ctxlua{lua.registercode("#1","#2")}}
\def\ctxloadluafile      #1{\ctxlua{lua.registercode("#1")}}

\registerctxluafile{luat-cod}{1.001}

% \everydump\expandafter{\the\everydump\ctxlua{lua.finalize()}}

\protect \endinput