lua-users home
lua-l archive

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


Il giorno Thu, 14 Jun 2012 10:02:07 +0200
Nicola Fontana <ntd@entidi.it> ha scritto:

> Il giorno Wed, 13 Jun 2012 22:40:31 -0700
> Paul K <paulclinger@yahoo.com> ha scritto:
> 
> > I suspect so too, but (1) it's not stated anywhere that it's against
> > the rules and (2) changing to "o[a] and 0 or 9" fixes it, which should
> > make no difference.
> > 
> > And I'm only reading the table, which should not trigger any
> > modification in it (even though it may be in some strange/intermediate
> > state).
> 
> I think the problem is your comparation logic. The following code
> raises the same problem without accessing the table:
> 
> a = {1,2,3,4}
> table.sort(a, function(a,b)
>     print(a, b)
>     return true
> end)
> 
> and this is what I get:
> 
> 4	1
> 2	4
> 3	4
> 4	4
> 1	4
> nil	4
> lua: a.lua:2: invalid order function for sorting
> stack traceback:
> 	[C]: in function 'sort'
> 	a.lua:2: in main chunk
> 	[C]: ?
> 
> It seems when compare returns invalid results (in the case above
> both row 1 and 5 return true with swapped values) a nil is introduced.

... a nil *can be* introduced.