ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Accessing string contents of a macro in Lua.
@ 2013-04-24 15:51 Sietse Brouwer
  2013-04-24 16:50 ` luigi scarso
  0 siblings, 1 reply; 3+ messages in thread
From: Sietse Brouwer @ 2013-04-24 15:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi all,

Below are three methods of defining a dimension / dimension string in
ConTeXt --- the first two boil down to storing a string in a macro,
the last is a proper TeX dimen. I want to access these dimensions from
Lua.

I can access the dimen via tex.dimen.ColumnC, but how can I access the
macro contents?
If there is no solution, I can always explicitly pass the value to Lua with

    \ctxlua{var = '\measure{ColumnA}'}

, but I want to know if there is a Lua-only method to get these values.

%% MWE
\definemeasure[ColumnA][10mm]

\def\ColumnB{20mm}

\newdimen\ColumnC
\ColumnC=30mm

\startluacode
    -- print values to stdout
    logs.report('====')
    logs.report('ColumnA', context.measure('ColumnA'))
    logs.report('ColumnB', context.ColumnB)
    logs.report('ColumnC', tex.dimen.ColumnC) -- prints in scaled points
    print('====')
\stopluacode

Cheers,
Sietse
___________________________________________________________________________________
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] 3+ messages in thread

* Re: Accessing string contents of a macro in Lua.
  2013-04-24 15:51 Accessing string contents of a macro in Lua Sietse Brouwer
@ 2013-04-24 16:50 ` luigi scarso
  2013-04-24 19:21   ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: luigi scarso @ 2013-04-24 16:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, Apr 24, 2013 at 5:51 PM, Sietse Brouwer <sbbrouwer@gmail.com> wrote:
> Hi all,
>
> Below are three methods of defining a dimension / dimension string in
> ConTeXt --- the first two boil down to storing a string in a macro,
> the last is a proper TeX dimen. I want to access these dimensions from
> Lua.
>
> I can access the dimen via tex.dimen.ColumnC, but how can I access the
> macro contents?
> If there is no solution, I can always explicitly pass the value to Lua with
>
>     \ctxlua{var = '\measure{ColumnA}'}
>
> , but I want to know if there is a Lua-only method to get these values.
>
> %% MWE
> \definemeasure[ColumnA][10mm]
>
> \def\ColumnB{20mm}

not a general solution
%%%
\def\ColumnB{20mm}

\starttext
\startluacode
local c = "\\csname ColumnB\\endcsname"
context("ColumnB=%s",c)
\stopluacode

\par
\toks0=\expandafter{\ColumnB}
\startluacode
context("ColumnB=%s",tex.toks[0])
\stopluacode

\stoptext




--
luigi
___________________________________________________________________________________
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] 3+ messages in thread

* Re: Accessing string contents of a macro in Lua.
  2013-04-24 16:50 ` luigi scarso
@ 2013-04-24 19:21   ` Hans Hagen
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2013-04-24 19:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 4/24/2013 6:50 PM, luigi scarso wrote:
> On Wed, Apr 24, 2013 at 5:51 PM, Sietse Brouwer <sbbrouwer@gmail.com> wrote:
>> Hi all,
>>
>> Below are three methods of defining a dimension / dimension string in
>> ConTeXt --- the first two boil down to storing a string in a macro,
>> the last is a proper TeX dimen. I want to access these dimensions from
>> Lua.
>>
>> I can access the dimen via tex.dimen.ColumnC, but how can I access the
>> macro contents?
>> If there is no solution, I can always explicitly pass the value to Lua with
>>
>>      \ctxlua{var = '\measure{ColumnA}'}
>>
>> , but I want to know if there is a Lua-only method to get these values.
>>
>> %% MWE
>> \definemeasure[ColumnA][10mm]
>>
>> \def\ColumnB{20mm}
%
> not a general solution
> %%%
> \def\ColumnB{20mm}

\newtoks\MyColumnB  \MyColumnB{20mm}

> \starttext
> \startluacode
> local c = "\\csname ColumnB\\endcsname"
> context("ColumnB=%s",c)
> \stopluacode
>
> \par
> \toks0=\expandafter{\ColumnB}
> \startluacode
> context("ColumnB=%s",tex.toks[0])

context("ColumnB=%s",tex.toks.MyColumnB)

> \stopluacode
>
> \stoptext
>
>
>
>
> --
> luigi
> ___________________________________________________________________________________
> 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] 3+ messages in thread

end of thread, other threads:[~2013-04-24 19:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-24 15:51 Accessing string contents of a macro in Lua Sietse Brouwer
2013-04-24 16:50 ` luigi scarso
2013-04-24 19:21   ` 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).