summaryrefslogtreecommitdiff
path: root/tex/context/base/luat-ini.tex
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/luat-ini.tex')
-rw-r--r--tex/context/base/luat-ini.tex104
1 files changed, 104 insertions, 0 deletions
diff --git a/tex/context/base/luat-ini.tex b/tex/context/base/luat-ini.tex
new file mode 100644
index 000000000..800950baf
--- /dev/null
+++ b/tex/context/base/luat-ini.tex
@@ -0,0 +1,104 @@
+%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:
+
+\def\dostartlua#1%
+ {\begingroup
+ \obeylualines
+ \directlua#1\iftrue{\else}\fi}
+
+\def\dostoplua
+ {\iffalse{\else}\fi
+ \endgroup}
+
+\def\dostartluacode#1%
+ {\begingroup
+ \obeylualines
+ \obeyluatokens
+ \directlua#1\iftrue{\else}\fi}
+
+\def\dostopluacode % no unexpanded, else no } seen
+ {\iffalse{\else}\fi
+ \endgroup}
+
+\def\startlua {\dostartlua \zerocount} \def\stoplua {\dostoplua}
+\def\startluacode{\dostartluacode\zerocount} \def\stopluacode {\dostopluacode}
+
+%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
+ {\catcode`\%=11 \catcode`\#=11
+ \catcode`\_=11 \catcode`\^=11
+ \catcode`\&=11 \catcode`\|=11
+ \catcode`\{=11 \catcode`\}=11
+ \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\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