Changes

Jump to navigation Jump to search
Describe argument parsing in Lua
< [[Inside ConTeXt]]
This article is based on a post on the mailing list by Taco Hoekwater from [[http://www.mail-archive.com/ntg-context@ntg.nl/msg03235.html 2004-06-28]]. == Using Lua ==
There is a lovely set of functions in the <tt>utilities.parsers</tt> table that turns strings into nice Lua-accessible tables of various kinds. An example is given below; the functions are documented on the [[String_Manipulation#util-prs.lua|string manipulation]] page. <texcode>\startluacodeuserdata = userdata or { } function userdata.mycommand(keywords, keyvals) keyword_options = utilities.parsers.settings_to_array(keywords) named_values = utilities.parsers.settings_to_hash(keyvals) -- do stuff based on that array and that hashtable.\stopluacode \def\mycommand[#1][#2]{\ctxlua{ userdata.mycommand('#1', '#2')}  \mycommand[top, inmargin, now][color=green, roof=gabled]</texcode> == Using TeX == This section is based on a post on the mailing list by Taco Hoekwater from [[http://www.mail-archive.com/ntg-context@ntg.nl/msg03235.html 2004-06-28]].  === Example code ===
<texcode>
</texcode>
=== Same example with commentary ===
The 'key' to the keyval functionality in ConTeXt are two macros called

Navigation menu