ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jaroslav Hajtmar <hajtmar@gyza.cz>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Dig out contents of the TeX macro using Lua
Date: Tue, 14 Jul 2015 22:41:15 +0200	[thread overview]
Message-ID: <55A573EB.4040201@gyza.cz> (raw)

Hello ConTeXist.
I hope that my crazy questions not much bother.
This time I needed to get to the fair value of the parameter, delivering 
to lua function over the content macros.
Obviously it's my misunderstanding of the functioning of expansion in 
case maker with optional parameters, or you really can not explain the 
functioning of the transmission values. It seems that is passed to a 
sort of reference as to the actual contents of the macro perhaps can not 
even get through Lua. Or did they?
The following minimal example, perhaps explain what going on.

The question ultimately: Is there any alternative how using Lua somehow 
easily evaluate the macro content? For example to determine whether two 
different macros have the same content?

Jaroslav Hajtmar

here is minimal example:

\starttext

This works as expected:

\def\makrowithAAAAcontent{AAAA}

\edef\testparameter#1{%
\startluacode
local parameter='#1'
if parameter=='AAAA' then context('TRUE. ') else context('FALSE. ') end
context('Parameter '..parameter..' has length '..string.len(parameter))
\stopluacode
}%

\type{\makrowithAAAAcontent} -- \makrowithAAAAcontent

Test is \testparameter{BBBB}

Test is \testparameter{AAAA} % OK

Test is \testparameter{\makrowithAAAAcontent} % OK

But what about with this: ???


% initialize values
\startluacode
A={}
for i=1,50 do A[i]='Record '..tostring(i) end
A[25]='AAAA'
\stopluacode


\def\makrowithAAAAcontent{AAAA}

\def\lastname{\dosingleempty\dolastname}%
\def\dolastname[#1]{\doifsomethingelse{#1}{\ctxlua{context(A[#1])}}{\makrowithAAAAcontent}}%


\type{\lastname} - \lastname

\type{\lastname[2]} - \lastname[2]

\type{\lastname[5]} - \lastname[5]

\type{\lastname[25]} - \lastname[25]





\edef\readandprocessparameters#1#2{%
\startluacode
local parameter1='#1'
if parameter1=='AAAA' then context('Test '..parameter1..' = AAAA is 
TRUE. ') else context('Test '..parameter1..' = AAAA is FALSE. ') end
context('Parameter 1 = '..parameter1..' has length 
'..string.len(parameter1))
context('\\crlf')
local parameter2='#2'
if parameter2=='AAAA' then context('Test '..parameter2..' = AAAA is 
TRUE. ') else context('Test '..parameter2..' = AAAA is FALSE. ') end
context('Parameter 2 = '..parameter2..' has length 
'..string.len(parameter2))
context('\\crlf')
\stopluacode
}%


\readandprocessparameters{AAAA}{BBBB}

%Test is \readandprocessparameters{\lastname[25]}{\lastname} % Crashed

\readandprocessparameters{\\lastname[25]}{\\lastname}

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

             reply	other threads:[~2015-07-14 20:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 20:41 Jaroslav Hajtmar [this message]
2015-07-15  7:01 ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55A573EB.4040201@gyza.cz \
    --to=hajtmar@gyza.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).