lua-users home
lua-l archive

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



I was unable to find a 'switch patch' to Lua 5.0 on the net. Has anyone done that / any other comfort-loving people that would like to have this syntax-sugar added to Lua?

Something in the lines of:

	switch expression do
		--
		case value1:
			--...
		case value2:
			--...
		case:
			--default
	end

I'd rather have it so that 'break' is not needed at the end of cases (this is good for making short, one line case constructs). 'continue' could be used to flow execution on to the next case..

The above would expand to:

	local tmp= expression
	if tmp==value1 then
		--...
	elseif tmp==value2 then
		--...
	else
		-- default
	end

Notice that 'expression' would be evaluated only once, and the values could be expressions, too (not constant).

-ak