From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/73618 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: CLD: context.getvariable as Lua variable Date: Thu, 5 Jan 2012 17:04:20 +0100 Message-ID: References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: multipart/mixed; boundary="===============0211779426==" X-Trace: dough.gmane.org 1325779482 904 80.91.229.12 (5 Jan 2012 16:04:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 16:04:42 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jan 05 17:04:38 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 1Ripnv-0007MY-8E for gctc-ntg-context-518@m.gmane.org; Thu, 05 Jan 2012 17:04:35 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0EFCDCB1D1; Thu, 5 Jan 2012 17:04:34 +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 oI-p4g3XuKS0; Thu, 5 Jan 2012 17:04:31 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 123C0CB1B4; Thu, 5 Jan 2012 17:04:31 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 36415CB1B4 for ; Thu, 5 Jan 2012 17:04:29 +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 cKoyvTdpT20j for ; Thu, 5 Jan 2012 17:04:27 +0100 (CET) Original-Received: from filter2-ams.mf.surf.net (filter2-ams.mf.surf.net [192.87.102.70]) by balder.ntg.nl (Postfix) with ESMTP id 2E130CB1B3 for ; Thu, 5 Jan 2012 17:04:27 +0100 (CET) Original-Received: from mail-ee0-f41.google.com (mail-ee0-f41.google.com [74.125.83.41]) by filter2-ams.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q05G4Qiq029953 for ; Thu, 5 Jan 2012 17:04:26 +0100 Original-Received: by eekc41 with SMTP id c41so555750eek.14 for ; Thu, 05 Jan 2012 08:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:mime-version:content-type:subject:date:in-reply-to:to :references:message-id:x-mailer; bh=nROQxIDfecyRlbbzBWneKbEWNoy6ew3mXe13qcBejZI=; b=s5CrUPO6BrGctRb4bNmE9ju4GEMCZVnTY7oGN3Ew3UKiIKTogS1t9ugS6XP9xvjyKf V4h2wmQy+CwUYqrz30tl6QILPMGyXc/kbgP3eFSUBveYpwmsQvbxBHZ6RQtk2lhgpfT+ Svg+LYabk2TsoKqizUSMlk/8mnKKMFr+iPD1A= Original-Received: by 10.213.3.196 with SMTP id 4mr587534ebo.120.1325779466107; Thu, 05 Jan 2012 08:04:26 -0800 (PST) Original-Received: from [192.168.2.35] (p57AFC0E2.dip.t-dialin.net. [87.175.192.226]) by mx.google.com with ESMTPS id q67sm173315609eea.8.2012.01.05.08.04.21 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jan 2012 08:04:24 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.1251.1) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=74.125.83.41; 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: 0rGhQ4qHm - 26f66f4211ac - 20120105 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.70 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:73618 Archived-At: --===============0211779426== Content-Type: multipart/alternative; boundary="Apple-Mail=_4CB51755-E9A4-4142-8590-D3DC014FC051" --Apple-Mail=_4CB51755-E9A4-4142-8590-D3DC014FC051 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Am 05.01.2012 um 15:49 schrieb Wagner Macedo: > Hello, >=20 > 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. >=20 > 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. >=20 > \starttext > \setvariable{namespace}{var}{Some context} > \ctxlua{ > local s =3D context.getvariable("namespace", "var") >=20 > if s =3D=3D "" then > ... > else > ... > end > } > \stoptext >=20 > 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 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 = and 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=20 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 --Apple-Mail=_4CB51755-E9A4-4142-8590-D3DC014FC051 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252
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 the 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
<= br>
\setvariable{wagner}{name}{Wagner = Macedo}

\starttext

\ctxl= ua{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 and 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
<= br>
\starttexdefinition SaveVariables
= \startlua
= userdata.macedo.savevariables{
= name    =3D = "\getvariable{macedo}{name}",
address =3D = "\getvariable{macedo}{address}",
}
= \stoplua
\stoptexdefinition

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

\starttex= t

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

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

\setvariables[macedo][address=3DSecret]

\ctxlua{userdata.macedo.checkvariables()}

<= /div>
\stoptext

Wolfgang

=
= --Apple-Mail=_4CB51755-E9A4-4142-8590-D3DC014FC051-- --===============0211779426== 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 ___________________________________________________________________________________ --===============0211779426==--