blob: 863530b6be1c1e8ca92979966c3b845a5f34dc36 (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
%D \module
%D [ file=luat-ini,
%D version=2005.08.11,
%D title=\CONTEXT\ Lua Macros,
%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
%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}{Lua Support Macros (initialization)}
\unprotect
%D We have to load this module in a very early stage. Therefore we
%D cannot rely on support macros being available.
% \long\def\rescan#1{\expanded{\scantextokens{#1}}}
%D Loading lua code can be done using \type {startup.lua}. The following
%D method uses the \TEX\ input file locator of kpse. At least we need to
%D use that way of loading when we haven't yet define our own code, which
%D we keep outside the format. We will keep code outside \TEX\ files as
%D much as possible.
\ifx\setnaturalcatcodes\undefined \let\setnaturalcatcodes\relax \fi
\ifx\obeylualines \undefined \let\obeylualines \relax \fi
\ifx\obeyluatokens \undefined \let\obeyluatokens \relax \fi
% \def\loadluacode#1#2% instance filename
% {\bgroup
% \everyeof{\noexpand}% hack to make \input nicely expandable
% \setnaturalcatcodes
% \obeylualines
% %message{[Lua Load: #2]}%
% \directlua#1\expandafter{\normalinput#2\space}\relax
% \egroup}
%D A few more goodies:
\long\def\dostartlua#1%
{\begingroup
\obeylualines
\dodostartlua{#1}}
\long\def\dodostartlua#1#2\stoplua
{\expanded{\endgroup\noexpand\directlua#1{#2}}}
\long\def\dostartluacode#1%
{\begingroup
\obeylualines
\obeyluatokens
\dodostartluacode{#1}}
\long\def\dodostartluacode#1#2\stopluacode
{\expanded{\endgroup\noexpand\directlua#1{#2}}}
\def\startlua {\dostartlua \zerocount}
\def\startluacode{\dostartluacode\zerocount}
%D Some delayed definitions:
\ifx\obeylines \undefined \let\obeylines \relax \fi
\ifx\obeyedline \undefined \let\obeyedline \relax \fi
\ifx\obeyspaces \undefined \let\obeyspaces \relax \fi
\ifx\obeyedspace \undefined \let\obeyedspace \relax \fi
\ifx\outputnewlinechar\undefined \let\outputnewlinechar\relax \fi
\def\obeylualines
{\obeylines \let\obeyedline \outputnewlinechar
\obeyspaces \let\obeyedspace\space}
\def\obeyluatokens % todo: make this a proper catcode table, use let's
{\catcode`\%=12 \catcode`\#=12
\catcode`\_=12 \catcode`\^=12
\catcode`\&=12 \catcode`\|=12
\catcode`\{=12 \catcode`\}=12
\catcode`\~=12 \catcode`\$=12
\def\\{\string\\}\def\|{\string\|}\def\-{\string\-}%
\def\({\string\(}\def\){\string\)}\def\{{\string\{}\def\}{\string\}}%
\def\'{\string\'}\def\"{\string\"}%
\def\n{\string\n}\def\r{\string\r}\def\f{\string\f}\def\t{\string\t}%
\def\a{\string\a}\def\b{\string\b}\def\v{\string\v}\def\s{\string\s}%
\def\1{\string1}\def\2{\string2}\def\3{\string3}\def\4{\string\4}\def\5{\string\5}%
\def\6{\string6}\def\7{\string7}\def\8{\string8}\def\9{\string\9}\def\0{\string\0}}
%D We provide an interface for defining instances:
\def\s!lua{lua} \def\v!code{code} \let\@EA\expandafter
\def\definelua[#1]%
{\ifcsname#1\s!lua\endcsname\else\expandafter\newlua\csname#1\s!lua\endcsname\fi
\setevalue{\e!start#1\s!lua }{\noexpand\dostartlua \csname#1\s!lua\endcsname}%
\setevalue{\e!start#1\s!lua\v!code}{\noexpand\dostartluacode\csname#1\s!lua\endcsname}%
\setvalue {\e!stop #1\s!lua }{\dostoplua }%
\setvalue {\e!stop #1\s!lua\v!code}{\dostopluacode}}
\definelua[CTX]
\protect \endinput
|