[NTG-context] final thoughts on experiments with lua
luigi.scarso at gmail.com
Wed Jan 9 21:12:19 CET 2019
On Wed, Jan 9, 2019 at 8:57 PM Thomas A. Schmitz <thomas.schmitz at uni-bonn.de>
> One final thought: one limitation that I still find cumbersome to work
> around is the fact that associative arrays ("pairs" in Lua speak) do not
> have an order. When I analyze my texts, I want book numbers, chapters,
> paragraphs preserved in the order in which they are read (entered into
> the table). In many cases, it is not possible (or extremely awkward) to
> sort these numbers, since chapters may be numbered something like 2, 2a,
> 3, 3α, 3β etc. python has the OrderedDict() in its collections module.
> In Lua, the best I could find was entering the chapter numbers into an
> array (ipair) and then retrieve it from there. Maybe there is a better way?
table.sort (list [, comp])
Sorts list elements in a given order, in-place, from list to
list[#list]. If comp is given, then it must be a function that receives two
list elements and returns true when the first element must come before the
second in the final order (so that, after the sort, i < j implies not
comp(list[j],list[i])). If comp is not given, then the standard Lua
operator < is used instead
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ntg-context