Ask Your Question

Revision history [back]

There is not a way to shorten your code to get that. They way you have it is idiomatic and (in my opinion) easy to read.

Here are a couple of options for longer, worse, and (probably) slower code. I don't recommend using them.

You could switch to a table lookup, but that's longer code.

if a == 0 and ({[1] = true, [3] = true, [5] = true})[b] then ...

You could define a helper function, but that's also longer code.

local function has_value(tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true

    return false

if a == 0 and has_value({1, 3, 5}, b) then

Again, your code is fine. I would leave it as-is.