luat-cod.mkiv /size: 2661 b    last modification: 2020-07-01 14:35
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
19
%D demanded 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
28
%D then at runtime, but when the amount grew, we realized that
29
%D we needed away to store them in the format, which is what
30
%D bytecode arrays do. And so the following is obsolete:
31
%D
32
%D \starttyping
33
%D \setnewconstant\ctxluaembeddingmode \plusone
34
%D
35
%D 0 = external compilation and loading
36
%D 1 = runtime compilation and embedding
37
%D \stoptyping
38
%D
39
%D Allocation of \LUA\ engines has changed too. The original idea
40
%D was to have multiple \LUA\ instances and it worked that way for
41
%D several years. Hoewver in practice we used only one engine because
42
%D scripts need to share data anyway. So eventually \LUATEX\ got only
43
%D one instance. Because each call is reentrant there is not much
44
%D danger for crashes.
45
%D
46
%D Most code here has changed after version 0.60 as part of adaption to
47
%D new functionality. We no longer support the hooks for initializing
48
%D code as this can be done at the \LUA\ end.
49 50
% we can drop the \zerocount as it's default
51 52
\let
\ctxdirectlua
\directlua
53
\let
\ctxlatelua
\latelua
54
\def
\ctxsprint
#
1
{
\directlua{
tex
.
sprint
(
tex
.
ctxcatcodes
,
#
1
)
}
}
% saves tokens
55
\def
\ctxwrite
#
1
{
\directlua{
tex
.
write
(
#
1
)
}
}
% saves tokens
56
\def
\ctxcommand
#
1
{
\directlua{
commands
.
#
1
}
}
% saves tokens
57
\def
\ctxdirectcommand
#
1
{
\directlua{
commands
.
#
1
}
}
% saves tokens
58
\def
\ctxlatecommand
#
1
{
\latelua {
commands
.
#
1
}
}
% saves tokens
59
\def
\ctxreport
#
1
{
\directlua{
logs
.
writer
[
[
#
1
]
]
}
}
60 61
%D Take your choice \unknown
62 63
\let
\ctxlua
\ctxdirectlua
64
\let
\luacode
\ctxdirectlua
65
\let
\lateluacode
\ctxlatelua
66
\let
\directluacode\ctxdirectlua
67 68
%D Reporting the version of \LUA\ that we use is done as follows:
69 70
\def
\luaversion
{
\ctxwrite
{
LUAVERSION
}}
71 72
\def
\registerctxluafile
#
1
#
2
{
\ctxlua{
lua
.
registercode
(
"
#1
"
,
"
#2
"
)
}
}
73
\def
\ctxloadluafile
#
1
{
\ctxlua{
lua
.
registercode
(
"
#1
"
)
}
}
74 75
\registerctxluafile
{
luat
-
cod
}{}
76 77
% \everydump\expandafter{\the\everydump\ctxlua{lua.finalize()}}
78 79
\protect
\endinput
80