[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")
-- context.YourGoTo("Index","ref:index")
-- context.YourGoTo(s,t)
-- context.goto("Index",{"ref:index"}) -- this does not work because goto is a rserved reserved word in Lua
\stopluacode
\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} \startluacodelocal value = tokens.getters.macro(tokens.getters.macro("??variables") .. "Namespace:Key")value = 3*valuecontext("Type: " .. type(value))context.par()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("Type: " .. type(value))
context.par()
context.setvariable("Namespace", "Key", value)
\stopluacode
Result is \getvariable{Namespace}{Key}.
\stopTEXpage
</context>
[[Category:Programming and Databases]]