luat-cod.mkiv / last modification: 2020-01-30 14:16
%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 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}


%D We cannot use the following due to the fact that existing usage
%D demanded duplicating hashes.
%D \starttyping
%D \def\expanded#1{\normalexpanded{\noexpand#1}} % ## mess
%D \stoptyping


%D Originally we compiled the \LUA\ files externally and loaded
%D then at runtime, but when the amount grew, we realized that
%D we needed away to store them in the format, which is what
%D bytecode arrays do. And so the following is obsolete:
%D \starttyping
%D \setnewconstant\ctxluaembeddingmode \plusone
%D 0 = external compilation and loading
%D 1 = runtime compilation and embedding
%D \stoptyping
%D Allocation of \LUA\ engines has changed too. The original idea
%D was to have multiple \LUA\ instances and it worked that way for
%D several years. Hoewver in practice we used only one engine because
%D scripts need to share data anyway. So eventually \LUATEX\ got only
%D one instance. Because each call is reentrant there is not much
%D danger for crashes.
%D Most code here has changed after version 0.60 as part of adaption to
%D new functionality. We no longer support the hooks for initializing
%D code as this can 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

%D Reporting the version of \LUA\ that we use is done as follows:


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


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

\protect \endinput