lua-users home
lua-l archive

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


Couldn't get any clearer, especially with that last table... perhaps, another FAQ candidate!
Thanks folks (also for the jumpstart to luac).


On Sun, Sep 22, 2013 at 6:23 PM, Philipp Janda <siffiejoe@gmx.net> 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