Changes

Jump to navigation Jump to search
863 bytes added ,  17:10, 25 November 2020
Added variables exchange (page should be renamed)
[ConTeXt-StandAlone]/tex/texmf-context/doc/context/documents/general/manuals/cld-mkiv.pdf
inside your ConTeXt directory.
 
= Macro arguments (parameters) =
Now if one needs to pass arguments from Lua to a macro command defined in ConTeXt, one has several possibilities.
\def\MyGoTo[#1][#2]{\goto{#1}[#2]}
\define[2]\YourGoTo{\goto{#1}[#2]}
\starttextstartTEXpage[offset=5mm]
\startchapter[title={Ward},reference={ch:ward}]
\startluacode
context.index("Knuth")
-- context.index("Ward")
context["index"]("Ward")
\stoptitle
\stoptextstopTEXpage
</context>
 
= Variables =
 
For setting variables command{{cmd|setvariable}} is used. One can retrieve the value with {{cmd|getvariable}}.
 
== From TeX to Lua ==
 
Setting variable on TeX end retrieving it at Lua side:
 
<context source=yes mode=mkiv>
\startTEXpage[offset=5mm]
 
\setvariable{Namespace}{Key}{30}
 
\startluacode
local value = tokens.getters.macro(tokens.getters.macro("??variables") .. "Namespace:Key")
value = 3*value
context("Result is " .. value)
\stopluacode
 
\stopTEXpage
</context>
 
 
== From Lua to TeX ==
 
Setting variable in Lua and retrieving it at TeX side:
 
<context source=yes mode=mkiv>
\startTEXpage[offset=5mm]
 
\startluacode
local value = 30
value = 3 * value
context.setvariable("Namespace", "Key", value)
\stopluacode
 
Result is \getvariable{Namespace}{Key}.
 
\stopTEXpage
</context>
 
[[Category:Programming and Databases]]
138

edits

Navigation menu