Something that isn't in default Lua

Post Reply
Demise
Posts: 4
Joined: Sat May 22, 2010 6:49 am

Something that isn't in default Lua

Post 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.....

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Something that isn't in default Lua

Post 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

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Something that isn't in default Lua

Post 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
> 

Demise
Posts: 4
Joined: Sat May 22, 2010 6:49 am

Re: Something that isn't in default Lua

Post 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

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Something that isn't in default Lua

Post 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.

Post Reply