lua-users home
lua-l archive

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


On Wed, Aug 26, 2015 at 1:44 PM, iain morland <iain@iainmorland.net> wrote:
> Thank you for the further responses. I now see that rhs/lhs was a red herring!
>
> Unfortunately I still don’t confidently grasp how the function works. Take the example in Roberto’s PiL book:
>
> table.sort(network, function(a,b) return (a.name > b.name) end)
>
> Presumably the function in the second argument returns true or false - right? Either a.name is greater than b.name or not.
>
> But what are a and b? Does table.sort repeatedly call the function using successive pairs of items from the table ‘network’ as arguments a and b?

Pretty much, yeah. I wouldn't describe them as "successive" -- it'll
call it whenever it needs to compare two items no matter where they
are in the input -- but it does get repeatedly called with various
pairs of items as necessary.

/s/ Adam