ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Christoph Reller <christoph.reller@gmail.com>
To: ntg-context <ntg-context@ntg.nl>
Subject: How to get parameters in lua
Date: Fri, 19 Sep 2014 09:30:42 +0200	[thread overview]
Message-ID: <CAO8LnPHg0+S=3BSHnND10OigDjYhtNu8XvTN19F6Sj4WGqmZ+Q@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1448 bytes --]

Hi,

\installcommandhandler nicely provides (among others) \define<name> and
\setup<name> commands. Thus it is easy to provide a key with
\setup...[key=value] and to read the value of such a key with
\<name>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.<name>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

[-- Attachment #1.2: Type: text/html, Size: 2138 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

             reply	other threads:[~2014-09-19  7:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19  7:30 Christoph Reller [this message]
2014-09-19  8:03 ` Hans Hagen
2014-09-20 12:45 Christoph Reller
2014-09-21 11:04 ` Hans Hagen

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='CAO8LnPHg0+S=3BSHnND10OigDjYhtNu8XvTN19F6Sj4WGqmZ+Q@mail.gmail.com' \
    --to=christoph.reller@gmail.com \
    --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).