summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/luat-cod.mkiv
blob: e7d58e8abe7b445acdf77819994f2344fb6c780e (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
%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 demanded
%D 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 then at runtime, but
%D when the amount grew, we realized that we needed away to store them in the
%D format, which is what 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 was to have
%D multiple \LUA\ instances and it worked that way for several years. Hoewver in
%D practice we used only one engine because scripts need to share data anyway. So
%D eventually \LUATEX\ got only one instance. Because each call is reentrant there
%D is not much danger for crashes.
%D
%D Most code here has changed after version 0.60 as part of adaption to new
%D functionality. We no longer support the hooks for initializing code as this can
%D 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:

\def\luaversion{\ctxwrite{LUAVERSION}}

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

\registerctxluafile{luat-cod}{}

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

\protect \endinput