ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* get tex-value in lua
@ 2010-05-04 10:12 Peter Münster
  2010-05-04 11:02 ` Peter Münster
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Münster @ 2010-05-04 10:12 UTC (permalink / raw)
  To: ConTeXt list

Hello,

How can I get the value of a variable or a mode in the lua part?

Example:

context --arguments=MyVar=true test

And in test.tex:

\starttext
\startluacode
local my_var = loadstring("return " .. get_value_of("MyVar"))
if my_var then
    tex.print("TRUE")
else
    tex.print("FALSE")
end
\stopluacode
\stoptext

TIA for any help!
Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/


___________________________________________________________________________________
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: get tex-value in lua
  2010-05-04 10:12 get tex-value in lua Peter Münster
@ 2010-05-04 11:02 ` Peter Münster
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Münster @ 2010-05-04 11:02 UTC (permalink / raw)
  To: ConTeXt list

On Tue, May 04 2010, Peter Münster wrote:

> How can I get the value of a variable or a mode in the lua part?

The solution is so simple... :

\ctxlua{userdata = userdata or {}; userdata.myvar = \env{MyVar}}
\starttext
\startluacode
if userdata.myvar then
    tex.print("TRUE")
else
    tex.print("FALSE")
end
\stopluacode
\stoptext

Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/


___________________________________________________________________________________
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:[~2010-05-04 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-04 10:12 get tex-value in lua Peter Münster
2010-05-04 11:02 ` Peter Münster

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).