Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [[
- Equivalent code for
- if color == "red" then
- print("Color is red")
- elseif color == "blue" then
- print("Color is blue")
- elseif color == "green" then
- print("Color is green")
- end
- ]]
- -- Assemble switch table
- local switch = {
- ["red"] = function() print("Color is red") end,
- ["blue"] = function() print("Color is blue") end,
- ["green"] = function() print("Color is green") end,
- }
- -- Get the function stored at switch[color], then call it
- what_to_do = switch[color]
- what_to_do()
- -- Or, the shorter alternative, just do
- -- switch[color]()
Advertisement
Add Comment
Please, Sign In to add comment