lua 实现switch 语句功能

print("********如何实现switch-case********")

local switch = {
    [1] = function()
        print ("case1")
    end,
    [2] = function()
        print ("case2")
    end,
    [3] = function()
        print ("case3")
    end
}


local a = 1

local f = switch[a]    -- 如==nil 则是false 

if(f) then
    print(type(f))
    f()
else
    print("case defaule")
end


--[[
-- 打印输出以下
-- ********如何实现switch-case********
-- case1
--]]
原文地址:https://www.cnblogs.com/axuanup/p/14028159.html