Hacker News new | ask | show | jobs
by SSchick 528 days ago
Sorry but this is 12 lines of Lua code, what is the value proposition/use case here? I'm legitimately curious.
1 comments

Honestly, not much.

I found it nice how it's possible to emulate switches in Lua with so little code, without the result looking too ugly. You may find this pattern useful. That's it.

The catch is that, unlike with normal switches or with a series of "if"s, there's a whole bunch of indirection added via functions, so it's not very efficient.

Perhaps LuaJIT can inline these functions, but I haven't tested it.