On 12/19/2012 9:13 PM, Troy Henderson wrote:
I got this to work. There's probably a better method though ;)
\edef\r{\luaexpr{1/3.8}}
\edef\q{1}\doloop{\ctxlua{commands.doifelse(math.abs(\q*\r -
math.floor(\q*\r+0.5))<0.000001)}{\exitloop}{\edef\q{\luaexpr{\q+1}}}}
Yes, you need to think more hybrid .. two variants:
\startluacode
local r = 1 / 3.8
local q = 1
while true do
if math.abs(q*r - math.floor(q*r+0.5)) < 0.000001 then
break
else
q = q + 1
end
end
context.setvalue("MyQ",q)
\stopluacode
\startluacode
userdata = userdata or { }
function userdata.CalculateQ(r)
local q = 1
while true do
if math.abs(q*r - math.floor(q*r+0.5)) < 0.000001 then
break
else
q = q + 1
end
end
context(q)
end
\stopluacode
\edef\MyOtherQ{\ctxlua{userdata.CalculateQ(1/3.8)}}
\starttext
q: \MyQ
q: \MyOtherQ
\stoptext
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________