ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Refreshing (synchronizing) values between Lua variables and TeX registers
@ 2012-06-18 13:02 Jaroslav Hajtmar
  2012-06-18 14:20 ` Hans Hagen
  0 siblings, 1 reply; 2+ messages in thread
From: Jaroslav Hajtmar @ 2012-06-18 13:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello ConTeXist and Lua experts

Is there any way to refresh values ​​between the values ​​stored in Lua 
code and TeX registers?
I need to evaluating the values of TeX registers (counters, dimensions, 
height of boxes, etc.) during the Lua cycle.
I would like in the cycle ​​read values from the TeX registers and write 
back there so that all values ​​were always synchronized.
Or I need advice on how to proceed. Most of my Lua code is in a separate 
file in Lua
function.

Is there a universal way to "jump out of cycle" to TeX synchronize all 
values ​​between TeX registers and Lua values (even at the cost of 
slowing down) and then go back into the cycle and continue?

I do not write cycles using the TeX macro language, but so far I'm 
failing in way around it.
What I need to I knowing or What I need to learn?

Thanx Jaroslav Hajtmar


The minimal example shows (maybe) what I mean:

\newcount\testcount

\def\countrefresh{\directlua{tex.count.testcount = tex.count.testcount + 1}}

\def\universalrefreshcommand{\directlua{-- ???}}

\def\printdebuginfo{
\directlua{tex.sprint(': ',tex.count.testcount, " - ", 
"\\the\\testcount","\\par")}
}

\starttext


Here values are not synchronized:

\testcount=0
\startluacode
local i=0
for i=1,5 do
tex.sprint(i)
tex.count.testcount = tex.count.testcount + 1
tex.sprint("\\printdebuginfo")
end
\stopluacode


\blank[big]

Here values of textcounter are synchronized:

\testcount=0
\startluacode
local i=0
for i=1,5 do
tex.sprint(i)
tex.sprint("\\countrefresh")
tex.sprint("\\printdebuginfo")
end
\stopluacode


\blank[big]


Is there a universal way to "jump out of cycle" to TeX synchronize all 
values ​​between TeX registers and Lua values (even at the cost of 
slowing down) and then go back into the cycle and continue?


\testcount=0
\startluacode
local i=0
for i=1,5 do
tex.sprint(i)
tex.count.testcount = tex.count.testcount + 1
tex.sprint("\\universalrefreshcommand")
tex.sprint("\\printdebuginfo")
end
\stopluacode


\blank[big]


\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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Refreshing (synchronizing) values between Lua variables and TeX registers
  2012-06-18 13:02 Refreshing (synchronizing) values between Lua variables and TeX registers Jaroslav Hajtmar
@ 2012-06-18 14:20 ` Hans Hagen
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2012-06-18 14:20 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users

On 18-6-2012 15:02, Jaroslav Hajtmar wrote:
> Hello ConTeXist and Lua experts
>
> Is there any way to refresh values ​​between the values ​​stored in Lua
> code and TeX registers?
> I need to evaluating the values of TeX registers (counters, dimensions,
> height of boxes, etc.) during the Lua cycle.
> I would like in the cycle ​​read values from the TeX registers and write
> back there so that all values ​​were always synchronized.
> Or I need advice on how to proceed. Most of my Lua code is in a separate
> file in Lua
> function.
>
> Is there a universal way to "jump out of cycle" to TeX synchronize all
> values ​​between TeX registers and Lua values (even at the cost of
> slowing down) and then go back into the cycle and continue?
>
> I do not write cycles using the TeX macro language, but so far I'm
> failing in way around it.
> What I need to I knowing or What I need to learn?
>
> Thanx Jaroslav Hajtmar
>
>
> The minimal example shows (maybe) what I mean:
>
> \newcount\testcount
>
> \def\countrefresh{\directlua{tex.count.testcount = tex.count.testcount +
> 1}}
>
> \def\universalrefreshcommand{\directlua{-- ???}}
>
> \def\printdebuginfo{
> \directlua{tex.sprint(': ',tex.count.testcount, " - ",
> "\\the\\testcount","\\par")}
> }
>
> \starttext
>
>
> Here values are not synchronized:
>
> \testcount=0
> \startluacode
> local i=0
> for i=1,5 do
> tex.sprint(i)
> tex.count.testcount = tex.count.testcount + 1
> tex.sprint("\\printdebuginfo")
> end
> \stopluacode
>
>
> \blank[big]
>
> Here values of textcounter are synchronized:
>
> \testcount=0
> \startluacode
> local i=0
> for i=1,5 do
> tex.sprint(i)
> tex.sprint("\\countrefresh")
> tex.sprint("\\printdebuginfo")
> end
> \stopluacode
>
>
> \blank[big]
>
>
> Is there a universal way to "jump out of cycle" to TeX synchronize all
> values ​​between TeX registers and Lua values (even at the cost of
> slowing down) and then go back into the cycle and continue?
>
>
> \testcount=0
> \startluacode
> local i=0
> for i=1,5 do
> tex.sprint(i)
> tex.count.testcount = tex.count.testcount + 1
> tex.sprint("\\universalrefreshcommand")
> tex.sprint("\\printdebuginfo")
> end
> \stopluacode

sure, as the 'prints' end up in the input buffer and are dealt with 
after the lua code has been dealt with; at some point we can have 
coroutines for going back and forth

in your case I'm not sure what is the problem as you can set the valus 
at the lua end and print the current value when needed

>
> \blank[big]
>
>
> \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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________


-- 

-----------------------------------------------------------------
                                           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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-18 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-18 13:02 Refreshing (synchronizing) values between Lua variables and TeX registers Jaroslav Hajtmar
2012-06-18 14:20 ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).