lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2015-11-29 1:40 GMT+02:00 Jonathan Goble <jcgoble3@gmail.com>:
> On Sat, Nov 28, 2015 at 6:37 PM, Daurnimator <quae@daurnimator.com> wrote:
>> local tSub = {
>>    {patt = "%-%-%-"; repl = "---"};
>>    {patt = "%-%-"; repl = "--"};
>>    {patt = "%.%."; repl = "..."};
>> }
>
> That's even better than what I suggested. I had a feeling someone
> would come in with a better solution. :)

I'm not claiming this is better, but some XML-to-Lua converters
do the attributes as a table with string keys, using integer keys
to order the keys.

{height=100, width=200, fg='red', bg='green', 'height', 'width', 'fg', 'bg'}

This allows standard random access, and in case you need it,
traversal by ipairs and indexing.

Of course, this use case assumes that ordered access is seldom
needed (only for reconstructing the original XML, in the cases
I have encountered).