ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* handling key=value sets with lua
@ 2011-01-09 22:13 Philipp A.
  2011-01-09 22:24 ` Hans Hagen
  2011-01-09 22:43 ` luigi scarso
  0 siblings, 2 replies; 4+ messages in thread
From: Philipp A. @ 2011-01-09 22:13 UTC (permalink / raw)
  To: ConTeXt Mainling List


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

hi list,

skip to the many %%% if you just want to help me ;)

i need to make a macro which consists of ten optional arguments. it wouldn’t
be too ugly to require to write the following to use it, since it outputs a
3×3 matrix with an adjacent tenth item, but tex can’t handle ten arguments
afaik.


syntax idea:
empty:
\bigcrafting%
{}{}{}%
{}{}{}{}%
{}{}{}%

partly filled:
\bigcrafting%
{}{}{}%
{planks}{planks}{}{workbench}%
{planks}{planks}{}%

how it should look:
[image: CraftingWorkbenchIO.png]

ok, since using empty “required” arguments aren’t elegent, either, i wanted
to get into key=value sets, but ran into the next problem:

i wanted to instead define bigcrafting to work like this:
\bigcrafting
  [21=planks, 22=planks,
   31=planks, 32=planks]
  [workbench]

but \getparameters<http://wiki.contextgarden.net/Commands_with_KeyVal_arguments>can’t
handle numerical values.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

and while points of the compass like NE, S and C (for center) would work, it
sprang to my mind that a parser written in lua, whitch uses lua’s internal
hashtables would meet my furter needs better (like looping over the matrix
and testing if parameters are set) can somebody tell my how to access (and
test if they exist) the arguments (#1,[#2],…) of a command definition in
lua?

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

[-- Attachment #2: Type: text/plain, Size: 486 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: handling key=value sets with lua
  2011-01-09 22:13 handling key=value sets with lua Philipp A.
@ 2011-01-09 22:24 ` Hans Hagen
  2011-01-09 22:41   ` Philipp A.
  2011-01-09 22:43 ` luigi scarso
  1 sibling, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2011-01-09 22:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 9-1-2011 11:13, Philipp A. wrote:

> i wanted to instead define bigcrafting to work like this:
> \bigcrafting
>    [21=planks, 22=planks,
>     31=planks, 32=planks]
>    [workbench]
>
> but \getparameters<http://wiki.contextgarden.net/Commands_with_KeyVal_arguments>can’t
> handle numerical values.

Why now?

\getparameters[MyNameSpace][1=a,2=b]

\getvalue{MyNameSpace1}

works ok.

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: handling key=value sets with lua
  2011-01-09 22:24 ` Hans Hagen
@ 2011-01-09 22:41   ` Philipp A.
  0 siblings, 0 replies; 4+ messages in thread
From: Philipp A. @ 2011-01-09 22:41 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users


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

2011/1/9 Hans Hagen <pragma@wxs.nl>

> On 9-1-2011 11:13, Philipp A. wrote:
>
>  i wanted to instead define bigcrafting to work like this:
>> \bigcrafting
>>   [21=planks, 22=planks,
>>    31=planks, 32=planks]
>>   [workbench]
>>
>> but \getparameters<
>> http://wiki.contextgarden.net/Commands_with_KeyVal_arguments>can’t
>> handle numerical values.
>>
>
> Why now?
>
> \getparameters[MyNameSpace][1=a,2=b]
>
> \getvalue{MyNameSpace1}
>
> works ok.
>

ok, i just knew of \MyNameSpaceKey, which doesn’t work if the key consists
numbers. thanks again!
ConTeXt seems to be your personal baby, isn’t it? ;)

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

[-- Attachment #2: Type: text/plain, Size: 486 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: handling key=value sets with lua
  2011-01-09 22:13 handling key=value sets with lua Philipp A.
  2011-01-09 22:24 ` Hans Hagen
@ 2011-01-09 22:43 ` luigi scarso
  1 sibling, 0 replies; 4+ messages in thread
From: luigi scarso @ 2011-01-09 22:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Sun, Jan 9, 2011 at 11:13 PM, Philipp A. <flying-sheep@web.de> wrote:

> hi list,
>
> skip to the many %%% if you just want to help me ;)
>
> i need to make a macro which consists of ten optional arguments. it
> wouldn’t be too ugly to require to write the following to use it, since it
> outputs a 3×3 matrix with an adjacent tenth item, but tex can’t handle ten
> arguments afaik.
>
>
> syntax idea:
> empty:
> \bigcrafting%
> {}{}{}%
> {}{}{}{}%
> {}{}{}%
>
> partly filled:
> \bigcrafting%
> {}{}{}%
> {planks}{planks}{}{workbench}%
> {planks}{planks}{}%
>
> how it should look:
> [image: CraftingWorkbenchIO.png]
>
> ok, since using empty “required” arguments aren’t elegent, either, i wanted
> to get into key=value sets, but ran into the next problem:
>
> i wanted to instead define bigcrafting to work like this:
> \bigcrafting
>   [21=planks, 22=planks,
>    31=planks, 32=planks]
>   [workbench]
>
> but \getparameters<http://wiki.contextgarden.net/Commands_with_KeyVal_arguments>can’t handle numerical values.
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> As Hans wrote it's possible, but I like the to use "row" for row, "col" for
column and "c" for cell
i.e
\def\BigCrafting[#1]%
{\getparameters[Ph][c11={},c12={},c13={},
c21={},c22={},c23={},c24={},
c31={},c32={},c33={},#1]
\bTABLE
\bTR\bTD\getvalue{Phc11}\eTD\bTD\getvalue{Phc12}\eTD\bTD\getvalue{Phc13}\eTD\eTR
\bTR\bTD\getvalue{Phc21}\eTD\bTD\getvalue{Phc22}\eTD\bTD\getvalue{Phc23}\eTD\bTD\getvalue{Phc24}\eTD\eTR
\bTR\bTD\getvalue{Phc31}\eTD\bTD\getvalue{Phc32}\eTD\bTD\getvalue{Phc33}\eTD\eTR
\eTABLE
}
\starttext
\BigCrafting[c11=FOO,c33=GOO,c22=BOO,c24=Zoo]
\BigCrafting[c11=FOO,c24=GOO]
\stoptext

You can also use a better namespace
\def\BigCrafting[#1]%
\unprotect
\getparameters[flying-sheep@web.de:][c11={},c12={},c13={},
c21={},c22={},c23={},c24={},
c31={},c32={},c33={},#1]
\getvalue{flying-sheep@web.de:c11}%%
\getvalue{flying-sheep@web.de:c12}%% and so on
\protect
}

-- 
luigi

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

[-- Attachment #2: Type: text/plain, Size: 486 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-09 22:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-09 22:13 handling key=value sets with lua Philipp A.
2011-01-09 22:24 ` Hans Hagen
2011-01-09 22:41   ` Philipp A.
2011-01-09 22:43 ` luigi scarso

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).