Created
July 27, 2025 16:18
-
-
Save LDDestroier/2f3acc222494548f68954ba58ff6a248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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