Skip to content

Instantly share code, notes, and snippets.

@aristotll
Forked from picsoung/switch.lua
Created July 7, 2016 13:16
Show Gist options
  • Save aristotll/fa6c130d5095a554e5c3a33171ef4760 to your computer and use it in GitHub Desktop.
Save aristotll/fa6c130d5095a554e5c3a33171ef4760 to your computer and use it in GitHub Desktop.
a switch in Lua
-- fct to simulate a switch
function switch(t)
t.case = function (self,x)
local f=self[x] or self.default
if f then
if type(f)=="function" then
f(x,self)
else
error("case "..tostring(x).." not a function")
end
end
end
return t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment