# [NTG-context] passing variables/data between context and lua

Martin Althoff martin.althoff at yahoo.com
Sun Sep 29 13:51:02 CEST 2019

```Thanks for the quick answers. Both suggestions work for me.

@Massi Thanks for the pointer into the cld-mkiv.pdf

@Wolfgang: I have to admit that I don't completely comprehend your solution, though it
works. Searching around for the commands you use, I came across an older posting you

https://mailman.ntg.nl/pipermail/ntg-context/2012/064326.html

That helps too. However I can find little documentation on the \setvariable/s commands.
I'll play around with the solution to understand it better.

> \defineexpandable\question{44}

> A solution which uses only existing commands in the document.
>
> \startsetups [martin]
>      \startlua
>          local points = tonumber(\getvariable{martin}{question}) or 0 ;
>                points = points * 92 ;
>          local answer = 42 ;
>          context.setvariable("martin","points",points) ;
>      \stoplua
> \stopsetups
>
> \setvariable{martin}{set}{\directsetup{martin}}
>
> \starttext
>
> \setvariables [martin] [question=44]
>
> Points: \getvariable{martin}{points}
>