lua-users home
lua-l archive

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


Hi

On Tue, Oct 27, 2009 at 11:01:55PM +0100, Alexander Walz wrote:
> The extended if structure would look something like this:
> 
> Old                      New
> 
> if cond1 then            if cond1 then
>    statement1              statement1
>    statementX
>    statementY
> elseif cond2             elseif cond 2 then
>    statement2              statement2
>    statementX
>    statementY
>                         finally  -- will always be executed of one cond 
> is true
>                            statementX
>                            statementY
> else                     else
>    other statements        other statements
> end;                     end;

that should translate to something like:

local _else -- if_with_finally_clause
if cond1 then
...
else
	other statements
_else = true end if ~ _else then -- finally
	statementX
	statementY
end

Should be possible using the token filter.
Obviously the if cases must not contain a break or return.


In plain Lua I would prefer
repeat
if cond1 then
...
else
	other statements
	break
end
-- finally
statementX
statementY
until true



cheers