From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/88724 Path: news.gmane.org!not-for-mail From: Christoph Reller Newsgroups: gmane.comp.tex.context Subject: How to get parameters in lua Date: Fri, 19 Sep 2014 09:30:42 +0200 Message-ID: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2057321588==" X-Trace: ger.gmane.org 1411111891 24329 80.91.229.3 (19 Sep 2014 07:31:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Sep 2014 07:31:31 +0000 (UTC) To: ntg-context Original-X-From: ntg-context-bounces@ntg.nl Fri Sep 19 09:31:27 2014 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 1XUsf7-00042i-N7 for gctc-ntg-context-518@m.gmane.org; Fri, 19 Sep 2014 09:31:25 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 2252C10223 for ; Fri, 19 Sep 2014 09:31:23 +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 Zx-9Tret+9to for ; Fri, 19 Sep 2014 09:31:23 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 3E7E610224 for ; Fri, 19 Sep 2014 09:31:15 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B6AC6101E3 for ; Fri, 19 Sep 2014 09:31: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 ZsNR5GbpKT5N for ; Fri, 19 Sep 2014 09:31:10 +0200 (CEST) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id 45484101E1 for ; Fri, 19 Sep 2014 09:31:04 +0200 (CEST) Original-Received: from mail-ie0-x22a.google.com (mail-ie0-x22a.google.com [IPv6:2607:f8b0:4001:c03::22a]) by filter4-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s8J7V3tY027397 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 19 Sep 2014 09:31:04 +0200 Original-Received: by mail-ie0-f170.google.com with SMTP id x19so6038ier.29 for ; Fri, 19 Sep 2014 00:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=yxipmsHBqiDaQCheDqdk0pXm2q0tB2KmuDZy5aAqYkU=; b=kvFMs+fnsnkz6NmPPdcbjEkd90WW0pStvlgZdtGiuaOxxADceJ7gNI9pOaQZc34SVp bu9GXUc4z530tUZfEnRn9XJ4HWJId8YDoeSb2eJN72wMw8ADbTdQjYDdhKMFvHapTCvd HIlTDfTSuK+A7rYPsNJZcXhK6/6raKWW5lS8lBwc4BGLw1FZYoIBj/+OnIze2ZlnhLsi eaVdYKIFyxDeQQDzdF377tnn3cYuE1RsT/DA9Vo8BSyZJsvITLCoyQBySFl91Kskt4+J kpVHApIWUrNjThVw6RN+6YSUQ9f4gSBbo0eu7IkOmWL/jw/BJ5f7XRBApu1SIws5cjAI cMHg== X-Received: by 10.50.138.194 with SMTP id qs2mr689554igb.4.1411111862487; Fri, 19 Sep 2014 00:31:02 -0700 (PDT) Original-Received: by 10.107.40.2 with HTTP; Fri, 19 Sep 2014 00:30:42 -0700 (PDT) X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2607:f8b0:4001:c03::22a; country=US X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 01MQTv4r7 - ef2947fdba11 - 20140919 (trained as not-spam) 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:88724 Archived-At: --===============2057321588== Content-Type: multipart/alternative; boundary=089e01183c904d53580503661525 --089e01183c904d53580503661525 Content-Type: text/plain; charset=UTF-8 Hi, \installcommandhandler nicely provides (among others) \define and \setup commands. Thus it is easy to provide a key with \setup...[key=value] and to read the value of such a key with \parameter{key}. My question is: How do I read the value of a key defined with \setup...[key=value] on the lua side? If I use context.parameter("key") then the value of key is printed directly. I want to be able to read that value and use it in lua with something like myvariable = context.?whatfunction?("key") Here is some example code: \unprotect \startluacode function myfun(parameters,content) context("From lua: Parameters: ") context(parameters) context.elemparameter("gkey") -- directly prints the parameter context.par() end \stopluacode \installnamespace{elem} \installcommandhandler \????elem {elem} \????elem \appendtoks \setuevalue{\currentelem}{\elem_cmd{\currentelem}}% \to \everydefineelem \unexpanded\def\elem_cmd#environment{% \edef\currentelem{#environment}% \dosingleempty\elem_cmd_parameters} \def\elem_cmd_parameters[#parameters]#content{% \setupcurrentelem[#parameters] From \TeX\: Parameters: key=\elemparameter{key}, gkey=\elemparameter{gkey}\par \ctxlua{myfun(\!!bs#parameters\!!es,\!!bs\normalunexpanded{#content}\!!es)} } \defineelem[base] \setupelem[gkey=gval] \protect \starttext \base[key=val]{Hello} \stoptext Thank you for any feedback, Christoph Reller --089e01183c904d53580503661525 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

\installcommandhandler nicely provi= des (among others) \define<name> and \setup<name> commands. Thu= s it is easy to provide a key with \setup...[key=3Dvalue] and to read the v= alue of such a key with \<name>parameter{key}.

My question is: How do I read the value of a key defined with \setup...[= key=3Dvalue] on the lua side? If I use
=C2=A0 context.<name>= ;parameter("key")
then the value of key is printed dire= ctly. I want to be able to read that value and use it in lua with something= like
=C2=A0 myvariable =3D context.?whatfunction?("key"= ;)

Here is some example code:

=
\unprotect

\startluacode
= =C2=A0 function myfun(parameters,content)
=C2=A0 =C2=A0 context(&= quot;From lua: Parameters: ")
=C2=A0 =C2=A0 context(paramete= rs)
=C2=A0 =C2=A0 context.elemparameter("gkey") -- dire= ctly prints the parameter
=C2=A0 =C2=A0 context.par()
= =C2=A0 end
\stopluacode

\installnamespac= e{elem}
\installcommandhandler \????elem {elem} \????elem
\appendtoks
=C2=A0 \setuevalue{\currentelem}{\elem_cmd{\curren= telem}}%
\to \everydefineelem

\unexpande= d\def\elem_cmd#environment{%
=C2=A0 \edef\currentelem{#environmen= t}%
=C2=A0 \dosingleempty\elem_cmd_parameters}

\def\elem_cmd_parameters[#parameters]#content{%
=C2=A0 \se= tupcurrentelem[#parameters]
=C2=A0 From \TeX\: Parameters: key=3D= \elemparameter{key}, gkey=3D\elemparameter{gkey}\par
=C2=A0 \ctxl= ua{myfun(\!!bs#parameters\!!es,\!!bs\normalunexpanded{#content}\!!es)}
}

\defineelem[base]
\setupelem[gke= y=3Dgval]

\protect

= \starttext

\base[key=3Dval]{Hello}

<= /div>
\stoptext

Thank you for any feedback,

Christoph Reller
--089e01183c904d53580503661525-- --===============2057321588== 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 ___________________________________________________________________________________ --===============2057321588==--