Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- switch case in Lua
- switch = function(check)
- return function(cases)
- if type(cases[check]) == "function" then
- return cases[check]()
- elseif type(cases["default"] == "function") then
- return cases["default"]()
- end
- end
- end
- -- example
- favoriteFood = "pilaf"
- switch(favoriteFood) {
- pilaf = function()
- print("That's some good rice")
- end,
- beef = function()
- print("Best when cooked")
- end,
- tetris = function()
- print("That's not a food")
- end,
- default = function()
- print("I don't get it")
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement