lua-users home
lua-l archive

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


On 22/07/2016 01:13, Rodrigo Azevedo wrote:
> I never ever
> used a "Lua array with holes", where the ordering, or existence, of the
> keys is indeed relevant for computation. 

I've used one in SILE's font fallback support - mapping characters in a
string to glyph IDs found in a set of fonts: "aβc" maps to

{
  [1] = { font = "Some Latin", glyphID = 1 },
  [2] = { font = "Some Greek", glyphID = 2 },
  [3] = { font = "Some Latin", glyphID = 3 },
}

If the character wasn't found in any font provided, you get a nil. Maybe
later this will get filled in by another font.

Sure, you could easily avoid nils in an array if you have a religious
aversion to them; just initialize the array with a bunch of "not-found"
sentinel values before running the fallback algorithm.

But I find it quite useful to have an easy way to tell that I went
looking for table.maxn(a) characters and only found #a of them.