Hi Jorge,
···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
just wrap the code in a macro. Lua code needs a different catcode
> I try make a table with some random numbers but I found a problem with this
> code:
>
>
> \starttext
> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
>
> \bTABLE
> \bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
> \bTR\bTD[nr=3] \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
> \eTD\bTD t1 \eTD\eTR
> \bTR\bTD t2 \eTD\eTR
> \bTR\bTD t3 \eTD\eTR
> \eTABLE
>
>
> \stoptext
>
> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
> inside the bTABLE environment.
regime and expansion rules that don’t cooperate well with the
table scanner. E.g.
\startluacode
local mathrandom = math.random
local context = context
document.get_random_number = function ()
context ("%0.1f", mathrandom (400, 600) / 10)
end
\stopluacode
\def \getrandomnumber {\ctxluacode {document.get_random_number ()}}
\starttext
\bTABLE\bTR \bTD[nr=3] \getrandomnumber \eTD \bTD t1 \eTD \eTR
\bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
\bTR \bTD t2 \eTD \eTRHth,
\bTR \bTD t3 \eTD \eTR
\eTABLE
\stoptext
Philipp
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________