lua-users home
lua-l archive

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


y = ((x==nil) and x) or (x+1) --?

Am 22.12.2014 um 16:58 schrieb Antonio Scuri:
  Hi,

   I would like to write something like this *in a single line*:

y = (x == nil)? x: x + 1

   If I do this:

y = testfunc(x == nil, x, x+1)

   and implement the "if" inside the function, I have the problem that
both expressions are evaluated before calling the function, and the
second expression will produce an error when x is nil.

   I'm not seeing the solution. Is this possible?

Thanks,
Scuri