%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 %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} \unprotect %D We cannot use the following due to the fact that existing usage demanded %D duplicating hashes. %D %D \starttyping %D \def\expanded#1{\normalexpanded{\noexpand#1}} % ## mess %D \stoptyping \newif\ifproductionrun %D Originally we compiled the \LUA\ files externally and loaded then at runtime, but %D when the amount grew, we realized that we needed away to store them in the %D format, which is what bytecode arrays do. And so the following is obsolete: %D %D \starttyping %D \setnewconstant\ctxluaembeddingmode \plusone %D %D 0 = external compilation and loading %D 1 = runtime compilation and embedding %D \stoptyping %D %D Allocation of \LUA\ engines has changed too. The original idea was to have %D multiple \LUA\ instances and it worked that way for several years. Hoewver in %D practice we used only one engine because scripts need to share data anyway. So %D eventually \LUATEX\ got only one instance. Because each call is reentrant there %D is not much danger for crashes. %D %D Most code here has changed after version 0.60 as part of adaption to new %D functionality. We no longer support the hooks for initializing code as this can %D 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 \let\directluacode\ctxdirectlua %D Reporting the version of \LUA\ that we use is done as follows: \def\luaversion{\ctxwrite{LUAVERSION}} \def\registerctxluafile#1#2{\ctxlua{lua.registercode("#1","#2")}} \def\ctxloadluafile #1{\ctxlua{lua.registercode("#1")}} \registerctxluafile{luat-cod}{} % \everydump\expandafter{\the\everydump\ctxlua{lua.finalize()}} \protect \endinput