Page 1 of 1

Something that isn't in default Lua

Posted: Thu Jun 03, 2010 1:30 am
by Demise
... but would be a nice addition not sure if possible to be coded in... ternary operator's

so many times I feel my self doing
x = (a > b) ? c : d

it is just .... a very very very nice thing.....

Re: Something that isn't in default Lua

Posted: Thu Jun 03, 2010 1:33 am
by tsuujin
Lua intentionally does not implement this sort of operator. They also don't use basic increment/decrement operators (++,--) or the "plusequals" operators ("+=, -=, /=,*=) which is a great frustration to me because I just don't understand why not.

i++
i += 1

is much easier and less keystroke happy than

i = i + 1

Re: Something that isn't in default Lua

Posted: Thu Jun 03, 2010 1:34 am
by Vadi
I'm against patching Lua in Mudlet. That said, you can just learn Lua a bit better; it already provides this:
Code: [show] | [select all] lua
> x = (5 > 4) and "a" or "b"
> print(x)
a
> x = (5 < 4) and "a" or "b"
> print(x)
b
> 

Re: Something that isn't in default Lua

Posted: Thu Jun 03, 2010 1:38 am
by Demise
Thanks didn't think they would be using bit wise operators like this instead thanks ;)

so many languages use that common format ... just figured ya couldn't do it that way

Re: Something that isn't in default Lua

Posted: Thu Jun 03, 2010 10:15 am
by Iocun
Not bitwise, but logical operators. Just that in Lua they are much more than the traditional boolean logical operators and have many more uses, such as the one Vadi just posted.