From: Hans Hagen <pragma@wxs.nl>
To: ntg-context@ntg.nl
Subject: Re: Passing macro parameters to lua
Date: Mon, 05 Aug 2013 23:00:11 +0200 [thread overview]
Message-ID: <5200125B.10504@wxs.nl> (raw)
In-Reply-To: <CABrD0edAuZFiRw=FMj1jNokEzAxUN=x1cj2tPPNTorLUn+0uWw@mail.gmail.com>
On 8/5/2013 10:53 PM, Matt Gushee wrote:
> Hello, good people--
>
> I've encountered what appears to be a bug in either the TeX->Lua
> interface or the documentation thereof (I have the latest stable
> ConTeXt standalone from contextgarden.net).
>
> I'm trying to create a macro that will insert different text depending
> on whether one of the arguments is empty or not. My initial test
> implementation (following the wiki section entitled "Passing arguments
> and buffers: ConTeXt commands that hook into Lua") looked like this:
>
> \startluacode
> userdata = userdata or {}
>
> function userdata.empty_or_not(str)
> if str == "" or str == nil then
> context("{\\sc Empty}")
> else
> context(str)
> end
> end
> \stopluacode
>
> \def\emptyOrNot#1{%
> \ctxlua{userdata.empty_or_not(#1)}%
> }
>
> \starttext
>
> \emptyOrNot{Amazing Text!}
>
> \emptyOrNot{}
>
> \stoptext
>
> This did not work. I determined that even when I passed a non-empty
> string, the Lua interpreter detected it as nil. It turns out the fix
> was simple--I had to quote the string, as follows.
>
> \def\emptyOrNot#1{%
> \ctxlua{userdata.empty_or_not("#1")}%
> }
>
> It took me a while to figure that out, though, since the wiki example
> does not show quotes.
indeed you need quotes
-----------------------------------------------------------------
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
___________________________________________________________________________________
next prev parent reply other threads:[~2013-08-05 21:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-05 20:53 Matt Gushee
2013-08-05 21:00 ` Hans Hagen [this message]
2013-08-05 21:35 ` Sietse Brouwer
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=5200125B.10504@wxs.nl \
--to=pragma@wxs.nl \
--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).