Skip to content

Instantly share code, notes, and snippets.

@LDDestroier
Created July 27, 2025 16:18
Show Gist options
  • Select an option

  • Save LDDestroier/2f3acc222494548f68954ba58ff6a248 to your computer and use it in GitHub Desktop.

Select an option

Save LDDestroier/2f3acc222494548f68954ba58ff6a248 to your computer and use it in GitHub Desktop.
function switch( expr, default )
return function( check )
for name, func in pairs(check) do
if expr == name then return func() end
end
if default then
assert(type(default) == "function", "default must be a function")
return default()
end
end
end
function matchsw( expr, default )
assert(type(expr) == "string", "expression must be string")
return function( check )
for name, func in pairs(check) do
if string.match(name, expr) then return func(expr) end
end
if default then
assert(type(default) == "function", "default must be a function")
return default(expr)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment