lua-users home
lua-l archive

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


On 22.09.2013 14:53, Philipp Janda wrote:
> Am 22.09.2013 14:10 schröbte Jayanth Acharya:
>>
>> So, if I understand this correctly, I cannot use the < and <=
>> operators in
>> Lua code while comparing 2 tables say 'a' and 'b', where the intent
>> was to
>> check (a < b). However I could rewrite the Lua code as (b > a). Right ?
>>
>> If so, then this is semantically correct, but makes the code less
>> readable,
>> no ?
>>
>     _________________________________________
>     |  you have   | you write |   Lua uses   |
>     |-------------|-----------|--------------|
>     | __lt only   |   a < b   |    a < b     |
>     | __lt only   |   a <= b  | not (b < a)  |
>     | __lt only   |   a > b   |    b < a     |
>     | __lt only   |   a >= b  | not (a < b)  |
>     | __lt + __le |   a < b   |    a < b     |
>     | __lt + __le |   a <= b  |    a <= b    |
>     | __lt + __le |   a > b   |    b < a     |
>     | __lt + __le |   a >= b  |    b <= a    |
>     | __le only   |   a < b   |   #error#    |
>     | __le only   |   a <= b  |    a <= b    |
>     | __le only   |   a > b   |   #error#    |
>     | __le only   |   a >= b  |    b <= a    |
>     ------------------------------------------
> 
> HTH,
> Philipp
> 

Awesome, thanks for that very helpful table :)