lua-users home
lua-l archive

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

> Am 28.01.2018 um 10:36 schrieb Dirk Laurie <>:
> 2018-01-28 10:52 GMT+02:00 KHMan <>:
>> I'd like a native switch. :-) Please, pretty pretty please :-)
> So which do you want? Like Pascal's 'case' statement [1]
> or like C's 'switch' statement?
> Personally I heartily detest the C 'switch'. You need to put
> 'break' all over the place. I never use the fall-through trick.
> It's a fast-track to lurking bugs.

Have you ever heard of duff's device?

> I am willing to keep an open mind on 'case'. I don't
> really think Lua needs it, but the workarounds are not pretty.

I usually create a table of functions and use the value I would use
in a C switch as the index.

That not only works well, but structures the code nicely and in
practive the function calling overhead is small.

> [1] I was a Pascal user from Wirth's first report until one
> needed p2c to run it under Linux. Now that Free Pascal
> has reached stability, I use Pacal again. Think of it as
> C with Lua readability. One can write Lua API code in
> Pascal and call Lua code from Pascal.