From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/83693 Path: news.gmane.org!not-for-mail From: Matt Gushee Newsgroups: gmane.comp.tex.context Subject: Passing macro parameters to lua Date: Mon, 5 Aug 2013 14:53:27 -0600 Message-ID: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1375736650 29068 80.91.229.3 (5 Aug 2013 21:04:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 5 Aug 2013 21:04:10 +0000 (UTC) To: "ConTeXt users' mailing list" Original-X-From: ntg-context-bounces@ntg.nl Mon Aug 05 23:04:14 2013 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V6Rn2-0000F6-Ki for gctc-ntg-context-518@m.gmane.org; Mon, 05 Aug 2013 22:54:04 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 61E93101E3; Mon, 5 Aug 2013 22:53:24 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AO4sciBH5uJX; Mon, 5 Aug 2013 22:53:13 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 0422F101E4; Mon, 5 Aug 2013 22:53:13 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 7F421101E4 for ; Mon, 5 Aug 2013 22:53:11 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 6u-9iM6tk9Jg for ; Mon, 5 Aug 2013 22:52:51 +0200 (CEST) Original-Received: from filter3-til.mf.surf.net (filter3-til.mf.surf.net [194.171.167.219]) by balder.ntg.nl (Postfix) with ESMTP id A1C5F101E3 for ; Mon, 5 Aug 2013 22:52:50 +0200 (CEST) Original-Received: from mail-oa0-x22d.google.com (mail-oa0-x22d.google.com [IPv6:2607:f8b0:4003:c02::22d]) by filter3-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id r75KrS6O006572 for ; Mon, 5 Aug 2013 22:53:29 +0200 Original-Received: by mail-oa0-f45.google.com with SMTP id m1so7446403oag.32 for ; Mon, 05 Aug 2013 13:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=Q6CzVA6Hl1qwGdMqQfH43gc8z0lXMi7yNRpQZRTqysE=; b=JQ5vCcyJJQxsC6Ft5uDYaRGe6I/1KpU2f3YOB0WO1xyoCfkzJ/zIguBQJ2ieKMPIkZ FFlLW+3yZEE+ByT7BYIKZvWg3b5yFOLG2I7zmArN3KUFM1+qnvWkiwVwSmSJOLkGSW4+ 8yzBvZ7PjPEMiZgJVUIOKh3exhhvPCtz+J5Dj6GRt2+q9fVXJl5786VxRZZmmNAjDwCm QCSqlp/7vQe0NiMliIo5bA4YWufKG9PG5f/lGvojnOvSBjOxhuTFQGUuXDJVjLkNnF4Q T8UfDl6031fRLJWfy4JiB61XvQNlv9CoP/uQnUr7Mb1P1ik6ldA0dx7pU5MWACshnkv2 3VMg== X-Received: by 10.43.74.74 with SMTP id yv10mr1843308icb.67.1375736007799; Mon, 05 Aug 2013 13:53:27 -0700 (PDT) Original-Received: by 10.42.144.74 with HTTP; Mon, 5 Aug 2013 13:53:27 -0700 (PDT) X-Google-Sender-Auth: csRCaLdKwprYOlU_za1oA9lQcyY X-Bayes-Prob: 0.6632 (Score 1, tokens from: @@RPTN) X-CanIt-Geo: ip=2607:f8b0:4003:c02::22d; country=US X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 06K98Rsfb - 1e1e3efecfe5 - 20130805 X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:83693 Archived-At: 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. -- Matt Gushee ___________________________________________________________________________________ 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 ___________________________________________________________________________________