From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/73620 Path: news.gmane.org!not-for-mail From: Wagner Macedo Newsgroups: gmane.comp.tex.context Subject: Re: CLD: context.getvariable as Lua variable Date: Thu, 5 Jan 2012 14:22:33 -0300 Message-ID: References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1722383830==" X-Trace: dough.gmane.org 1325784205 7110 80.91.229.12 (5 Jan 2012 17:23:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 17:23:25 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jan 05 18:23:20 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rir28-0006kg-6a for gctc-ntg-context-518@m.gmane.org; Thu, 05 Jan 2012 18:23:20 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C27E6CB1C3; Thu, 5 Jan 2012 18:23:18 +0100 (CET) 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 yqqgS8e3oNaH; Thu, 5 Jan 2012 18:23:13 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1C9BECB1B4; Thu, 5 Jan 2012 18:23:13 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C0C9DCB1B4 for ; Thu, 5 Jan 2012 18:23:11 +0100 (CET) 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 1TsW5RvYvCDz for ; Thu, 5 Jan 2012 18:22:57 +0100 (CET) Original-Received: from filter4-til.mf.surf.net (filter4-til.mf.surf.net [194.171.167.220]) by balder.ntg.nl (Postfix) with ESMTP id 69A7FCB1A2 for ; Thu, 5 Jan 2012 18:22:57 +0100 (CET) Original-Received: from mail-iy0-f169.google.com (mail-iy0-f169.google.com [209.85.210.169]) by filter4-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q05HMtbs019592 for ; Thu, 5 Jan 2012 18:22:55 +0100 Original-Received: by iacb35 with SMTP id b35so1548054iac.14 for ; Thu, 05 Jan 2012 09:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=t6IP2pOLzUPD9HodmMW2Tkgovif6IsZtAatVGbM2e9E=; b=Dvh+ZW62sf7IvtXxNbmS1nAeEVMbzNQ5S1WIK6cn8B3AL2awVAMijJBbSmyG1MXLcb /XjBmA6F1pM5gF16/LyfyPWoCjiqa/4VJYebs5/5CPFFNVTa9z92N58hqwByO9CJs8dl U8tFX5wQ2bifU1tQ32ViVGtQ4Zma5zQn+Gqk8= Original-Received: by 10.42.135.69 with SMTP id o5mr3394730ict.34.1325784174575; Thu, 05 Jan 2012 09:22:54 -0800 (PST) Original-Received: by 10.231.117.223 with HTTP; Thu, 5 Jan 2012 09:22:33 -0800 (PST) In-Reply-To: X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.210.169; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 05GhRmTc4 - 51c29d30bab2 - 20120105 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.220 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:73620 Archived-At: --===============1722383830== Content-Type: multipart/alternative; boundary=90e6ba6e836cc63f7504b5cb2e8d --90e6ba6e836cc63f7504b5cb2e8d Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Firstly, thanks by answer. The second way is nice, but could be generic (e.g. save any variable in a namespace)? -- Wagner Macedo On 5 January 2012 13:04, Wolfgang Schuster wrote: > > Am 05.01.2012 um 15:49 schrieb Wagner Macedo: > > Hello, > > I'm relatively quite new to TeX world. This is my first message to list. = I > hope you understand me, English isn't my mother language. > > I'm trying to use a variable set by \setvariable in Lua. I tried some > combinations, based on manual but I couldn't succeed. The code below > exemplifies what I wanted to do. > > \starttext > \setvariable{namespace}{var}{Some context} > \ctxlua{ > local s =3D context.getvariable("namespace", "var") > > if s =3D=3D "" then > ... > else > ... > end > } > \stoptext > > I know that I can use some of \if* TeX commands, but coding in Lua is > better to me. > > > What you=92re trying is not possible but there are other ways to check th= e > content of the variable in Lua. > > \startluacode > > userdata =3D userdata or { } > > function userdata.checkvariable(variable) > if variable =3D=3D "" then > context("EMPTY") > else > context("NOT EMPTY") > end > end > > \stopluacode > > \setvariable{wagner}{name}{Wagner Macedo} > > \starttext > > \ctxlua{userdata.checkvariable("\getvariable{wagner}{name}")} > > % This does only with \startlua or \ctxlua > > \startlua > > local name =3D "\getvariable{wagner}{name}" > > if name =3D=3D "" then > context("No Text") > else > name =3D "Name: " .. name > context(name) > end > > \stoplua > > \stoptext > > A different method is to save the \setvariables entries in a Lua table an= d > check the entries of the table. > > \startluacode > > userdata =3D userdata or { } > userdata.macedo =3D userdata.macedo or { } > > userdata.macedo.data =3D { } > > function userdata.macedo.savevariables(variables) > userdata.macedo.data =3D variables > end > > function userdata.macedo.checkvariables() > local variables =3D userdata.macedo.data > -- check for name > if variables.name =3D=3D "" then > context("Name: No name set") > context.par() > else > context("Name: "..variables.name) > context.par() > end > -- check for address > if variables.address =3D=3D "" then > context("Address: No address set") > context.par() > else > context("Address: "..variables.address) > context.par() > end > end > > \stopluacode > > \starttexdefinition SaveVariables > \startlua > userdata.macedo.savevariables{ > name =3D "\getvariable{macedo}{name}", > address =3D "\getvariable{macedo}{address}", > } > \stoplua > \stoptexdefinition > > \setvariables[macedo][set=3D\SaveVariables] > > \starttext > > \setvariables[macedo][name=3DWagner Macedo] > > \ctxlua{userdata.macedo.checkvariables()} > > \setvariables[macedo][address=3DSecret] > > \ctxlua{userdata.macedo.checkvariables()} > > \stoptext > > Wolfgang > > > > _________________________________________________________________________= __________ > 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 > > _________________________________________________________________________= __________ > --90e6ba6e836cc63f7504b5cb2e8d Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Firstly, thanks by answer.

The second way is nice, but could be gene= ric (e.g. save any variable in a namespace)?

--
Wagner Macedo

On 5 January 2012 13:04, Wolfgang Schust= er <schuster.wolfgang@googlemail.com> wrote:

Am 05.01.2012 um 15:49 sc= hrieb Wagner Macedo:

Hello,

I'm relatively quite new to TeX world. This is my fir= st message to list. I hope you understand me, English isn't my mother l= anguage.

I'm trying to use a variable set by \setvariable in Lua. I tried so= me combinations, based on manual but I couldn't succeed. The code below= exemplifies what I wanted to do.

\starttext
\setvariable= {namespace}{var}{Some context}
\ctxlua{
=A0 local s =3D context.getvariable("namespace", &qu= ot;var")

=A0 if s =3D=3D "" then
=A0=A0= =A0 ...
=A0 else
=A0=A0=A0 ...
=A0 end
\stoptext

I= know that I can use some of \if* TeX commands, but coding in Lua is better= to me.

What you=92re= trying is not possible but there are other ways to check the content of th= e variable in Lua.

\startluacode

userdata =3D userdata = or { }

function userdata.checkvariable(variable)
if variable =3D=3D &q= uot;" then
context("EMPTY"= ;)
else
context("NOT EMPTY")<= /div>
end
end

\stopluacode

\setvariable{wagner= }{name}{Wagner Macedo}

\starttext

\ctxlua{userdata.checkvariable("\getvariable{wagner}{name}&= quot;)}

% This does only with \startlua or \ctxlua=

\startlua

local name =3D= "\getvariable{wagner}{name}"

if name =3D=3D "" then
context("No Text")
el= se
name =3D "Na= me: " .. name
context(name)
e= nd

\stoplua

\stoptext

A different method is to save the \setvariables= entries in a Lua table and check the entries of the table.

\startluacode

userdata = =A0 =A0 =A0 =A0=3D userdata =A0 =A0 =A0 =A0or { }
userdata.macedo= =3D userdata.macedo or { }

userdata.macedo.data = =3D { }

function userdata.macedo.savevariables(variables)
userdata.macedo.data =3D variables=
end

function userdata.macedo.checkvaria= bles()
local variables =3D userd= ata.macedo.data
-- c= heck for name=A0
if = variables.name =3D= =3D "" then
context("Name: No n= ame set")
cont= ext.par()
else
=
context("Name: "..<= a href=3D"http://variables.name" target=3D"_blank">variables.name)
context.par()
end
-- check for address
if variables.address =3D= =3D "" then
context("Address: No address set")
context.par()
= else
context("Address: "..variables.add= ress)
context.par()
= end
end
\stopluacode

\starttexdefinition Save= Variables
\startlua
userdata.macedo.savevariables{
name =A0 =A0=3D "= ;\getvariable{macedo}{name}",
address =3D "\getv= ariable{macedo}{address}",
}
\stop= lua
\stoptexdefinition

\setvariables[macedo][set= =3D\SaveVariables]

\starttext

=
\setvariables[macedo][name=3DWagner Macedo]

\= ctxlua{userdata.macedo.checkvariables()}

\setvariables[macedo][address=3DSecret]

<= /div>
\ctxlua{userdata.macedo.checkvariables()}

\stoptext
=
Wolfgang


___________= ________________________________________________________________________ If your question is of interest to others as well, please add an entry to t= he Wiki!

maillist : ntg-context@ntg.nl / <= a href=3D"http://www.ntg.nl/mailman/listinfo/ntg-context" target=3D"_blank"= >http://www.ntg.nl/mailman/listinfo/ntg-context
webpage =A0: http://= www.pragma-ade.nl / http://tex.aanhet.net
archive =A0: http://foundry.supelec.fr/projects/contextrev/
wiki =A0 =A0 : http:= //contextgarden.net
___________________________________________________________________________= ________

--90e6ba6e836cc63f7504b5cb2e8d-- --===============1722383830== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --===============1722383830==--