summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/luacode/luacode.sty
blob: f8de0e467d3b4c2b57f3c5c2c91342788349105a (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
%%
%% This is file `luacode.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% luacode.dtx  (with options: `texpackage')
%% 
%% See the source file for author and licensing information.
%% 
\begingroup\catcode61\catcode48\catcode32=10\relax% = and space
  \catcode123 1 % {
  \catcode125 2 % }
  \catcode 35 6 % #
  \toks0{\endlinechar\the\endlinechar}%
  \edef\x{\endlinechar13}%
  \def\y#1 #2 {%
    \toks0\expandafter{\the\toks0 \catcode#1 \the\catcode#1}%
    \edef\x{\x \catcode#1 #2}}%
  \y  13  5 % carriage return
  \y  61 12 % =
  \y  32 10 % space
  \y 123  1 % {
  \y 125  2 % }
  \y  35  6 % #
  \y  64 11 % @ (letter)
  \y  39 12 % '
  \y  40 12 % (
  \y  41 12 % )
  \y  42 12 % *
  \y  45 12 % -
  \y  46 12 % .
  \y  47 12 % /
  \y  91 12 % [
  \y  93 12 % ]
  \y  94  7 % ^
  \y  96 12 % `
  \y 126 13 % ~
  \toks0\expandafter{\the\toks0 \relax\noexpand\endinput}%
  \edef\y#1{\noexpand\expandafter\endgroup%
    \noexpand\ifx#1\relax \edef#1{\the\toks0}\x\relax%
    \noexpand\else \noexpand\expandafter\noexpand\endinput%
    \noexpand\fi}%
\expandafter\y\csname luacode@sty@endinput\endcsname%
\ProvidesPackage{luacode}[2012/01/23 v1.2a lua-in-tex helpers (mpg)]
\RequirePackage{ifluatex}
\ifluatex\else
  \PackageError{luacode}{LuaTeX is required for this package. Aborting.}{%
    This package can only be used with the LuaTeX engine\MessageBreak
    (command `lualatex'). Package loading has been stopped\MessageBreak
    to prevent additional errors.}
  \expandafter\luacode@sty@endinput
\fi
\RequirePackage{luatexbase}
\newcommand \luacode@printdbg [1] {%
  texio.write_nl('log',
    '-- BEGIN luacode debug (on input line \the\inputlineno)')
  texio.write_nl('log', "\luatexluaescapestring{#1}")
  texio.write_nl('log',
    '-- END luacode debug (on input line \the\inputlineno)')
}
\newcommand \luacode@dbg@exec [1] {%
  \directlua {
    \luacode@maybe@printdbg{#1}
    #1
  }%
}
\begingroup \catcode`\~\active \expandafter\endgroup
\@firstofone{%
  \newcommand \luacode@execute [1] {%
    \begingroup
    \escapechar92
    \newlinechar10
    \edef\\{\string\\}%
    \edef~{\string~}%
    \let\%=\luacode@percentchar
    \let\#=\luacode@sharpchar
    \expandafter\expandafter\expandafter\endgroup
    \luacode@dbg@exec{#1}}
}
\begingroup \escapechar\m@ne \edef\aux{\endgroup
  \unexpanded{\newcommand\luacode@percentchar}{\string\%}%
  \unexpanded{\newcommand\luacode@sharpchar  }{\string\#}%
}\aux
\newcommand*\luacode@begin [1] {%
  \begingroup
  \escapechar92
  \luatexcatcodetable#1\relax
  \edef\luacode@endmark{\string\end{\@currenvir}}%
  \expandafter\def \expandafter\luacode@endmark \expandafter{%
    \luatexscantextokens \expandafter{\luacode@endmark}}%
  \luacode@grab@body}
\newcommand\luacode@end{%
  \edef\luacode@next{%
    \noexpand\luacode@execute{\the\luacode@lines}%
    \noexpand\end{\@currenvir}}%
  \expandafter\endgroup
  \luacode@next}
\newtoks\luacode@lines
\newcommand*\luacode@addline [1] {%
  \luacode@lines\expandafter{\the\luacode@lines#1^^J}}
\newcommand \luacode@grab@body [1] {%
  \luacode@lines{}%
  \endlinechar10
  \luacode@grab@lines}
\long\def\luacode@grab@lines#1^^J{%
  \def\luacode@curr{#1}%
  \luacode@strip@spaces
  \ifx\luacode@curr\luacode@endmark
    \expandafter\luacode@end
  \else
    \expandafter\luacode@addline\expandafter{\luacode@curr}%
    \expandafter\luacode@grab@lines
  \fi}
\begingroup\catcode32 12 \expandafter\endgroup
\@firstofone{\newcommand\luacode@spaceother{ }}
\newcommand \luacode@strip@spaces {%
  \expandafter\luacode@strip@sp@peek\luacode@curr\@nil}
\newcommand \luacode@strip@sp@peek {%
  \futurelet\@let@token\luacode@strip@sp@look}
\newcommand \luacode@strip@sp@look {%
  \expandafter\ifx\luacode@spaceother\@let@token
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi{%
    \afterassignment\luacode@strip@sp@peek
    \let\@let@token=
  }{%
    \luacode@strip@sp@def
  }}
\@ifdefinable \luacode@strip@sp@def \relax
\def \luacode@strip@sp@def #1\@nil{%
  \def\luacode@curr{#1}}
\newluatexcatcodetable \luacode@table@soft
\begingroup
\ifdefined\SetCatcodeRange \else
  \let\SetCatcodeRange\setcatcoderange
\fi
\setluatexcatcodetable \luacode@table@soft {%
  \luatexcatcodetable\CatcodeTableOther
  \catcode 92  0
  \catcode 123 1
  \catcode 125 2
  \SetCatcodeRange {65}{90} {11}
  \SetCatcodeRange {97}{122}{11}
}
\endgroup
\newcommand \LuaCodeDebugOn  {\let \luacode@maybe@printdbg \luacode@printdbg}
\newcommand \LuaCodeDebugOff {\let \luacode@maybe@printdbg \@gobble}
\LuaCodeDebugOff
\@ifdefinable\luadirect {\let\luadirect\luacode@dbg@exec}
\newcommand*\luaexec [1] {\luacode@execute{#1}}
\newenvironment {luacode}  {\luacode@begin\luacode@table@soft} {}
\newenvironment {luacode*} {\luacode@begin\CatcodeTableOther}  {}
\newcommand     \luacodestar    {\@nameuse{luacode*}}
\def            \endluacodestar {\@nameuse{endluacode*}}
\newcommand \luastring   [1] {"\luatexluaescapestring{#1}"}
\newcommand \luastringO  [1] {\luastring{\unexpanded\expandafter{#1}}}
\newcommand \luastringN  [1] {\luastring{\unexpanded{#1}}}
\luacode@sty@endinput
\endinput
%%
%% End of file `luacode.sty'.