lua-users home
lua-l archive

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

On Sun, Sep 12, 2010 at 7:19 PM, Drake Wilson <> wrote:
> In a Lua variant I have sitting
> around locally, I use a preprocessor that includes n-ary conditional
> operator with equivalent syntax to the if/then/elseif/then/else/end
> statement but with expressions instead of statements.  It converts the
> expression as:
>  if a then b elseif c then d else e end
>  ==> _PP.expr_if((( a ) and _PP.expr_then( b ))
>                  or (( c ) and _PP.expr_then( d ))
>                  or (_PP.expr_then( e )) or nil)

The run-time overhead that that adds can be avoided.  It is possible
to mechanically translate expression ifs into their statement format.
Something related to that was done in [1] -- i.e. first rewrite it in
terms of an anonymous function and then inline the function.  To some
extent you can also preserve line numbers across the translation to
lesson the impact on debugging info, but it might not be perfect [2],
and I haven't tried.  Overall it's not the simplest thing to do