\starttext \define\question{44} \startluacode -- see "ConTeXt Lua Documents" manual, ยง7.4 Looking inside local question = tokens.getters.macro("question") -- it's up to you to verify that \question contains a number -- better using the userdata table for your data userdata.points = tonumber( question ) * 92 -- do some calculations with points and return to to context userdata.answer=42 \stopluacode % lots of Text in between The answer is \ctxlua{ context(userdata.answer) }. Points are \ctxlua{ context(userdata.points) }. \stoptext Best wishes, Massi Il 27/09/19 06:59, Martin Althoff ha scritto:
Hi, I am trying to pass variables/data between context and lua. Lua would be used for calculations on data coming from context.
Unfortunately I can't figure out what to do. The code below doesn't work, but is there to illustrate my idea.
Any help would be much appreciated. Thanks, Martin
\define\question{44}
\starttext
\startluacode local points = \question * 92 -- do some calculations with points and return to to context answer=42 \stopluacode
% lots of Text in between The answer is \answer
\stoptext
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________