Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function testFunc(tag)
- print(tag)
- end
- local function testFunc2(tag)
- for k=0,3 do
- print(k.." : "..tag)
- end
- end
- local function testFunc3(x,y,z)
- for k=0,3 do
- print("X:"..x.." Y:"..y.." Z:"..z)
- end
- return 7777
- end
- switch1 = {
- [1] = function(tag,x,y,z) testFunc(tag) end,
- [2] = function(tag,x,y,z) testFunc2(tag) end,
- [3] = function(tag,x,y,z) return testFunc3(x,y,z) end,
- ['default'] = function() print("defaulted") end,
- }
- local func = switch1[4]
- if(func) then
- func("myName",-2,10,5.0)
- else
- print " The program has been terminated."
- print " Thank you!";
- end
- function switch(param,tag,x,y,z,case_table)
- local case = case_table[param]
- if case then return case(tag,x,y,z) end
- local def = case_table['default']
- return def and def() or nil
- end
- local s = switch(1,"pr0ngus",7,5,5,switch1)
- print(s)
- s = switch(2,"pr0ngus",7,5,5,switch1)
- print(s)
- s = switch(3,"pr0ngus",7,5,5,switch1)
- print(s)
- s = switch(4,"pr0ngus",7,5,5,switch1)
- print(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement