Changes

Jump to navigation Jump to search
m
→‎Undefined Commands in Lua Comments: Fix a broken link. And add enough information to be able to re-fix it easily. (I guess this last part could go in a footnote reference, but I am not sure how to do that properly…)
There are two main ways to execute Lua code in a ConTeXt document: The command {{cmd|ctxlua}}, and the environment {{cmd|startluacode}}…{{cmd|stopluacode}}. Both are wrappers around the LuaTeX primitive {{cmd|directlua}}, which you should never need to use. In general, you will define a function inside a {{cmd|startluacode}} block, and then define a TeX command that calls the function using {{cmd|ctxlua</code>, especially because {{cmd|ctxlua}} has a few idiosyncracies.
<blockquote>The main thing about Lua code in a TeX document is this: the code is expanded by TeX ''before'' Lua gets to it. '''This means that all the Lua code, even the comments, must be valid TeX!''' A string like {{cmd|undefined}} will cause an immediate failure.</blockquote>
== Calling a bit of Lua inline: {{cmd|ctxlua}} ==
</texcode>
The full list of canonical namespaces, taken from [httphttps://minimalsdistribution.contextgarden.net/current/context/alphalatest/tex/context/base/mkxl/luat-ini.lua lmt luat-ini.lualmt]:
<code><pre>
</texcode>
To get the sample above working (as [https://mailmanwww.ntgmail-archive.nl/pipermailcom/ntg-context@ntg.nl/2023/107611msg103892.html explained by Hansin a NTG-context thread from jan. 2023 entitled “Minor bug in Lua or ConTeXt”]), you would need a fallback definition:
<texcode>
2

edits

Navigation menu