function test1()
print("test1")
print(test1)
end
function test2(val)
print(val)
end
local switch = {
test1 = test1,
t2 = test2,
}
local t1 = switch["test1"]
t1()
print(t1)
print("------")
local t2 = switch["t2"]
t2(3)
lua中table可以实现类似switch的语法。
本文介绍了一种在Lua编程语言中使用table来模拟switch-case语句的方法。通过定义局部变量和table映射的方式实现了不同函数的选择调用。

1194

被折叠的 条评论
为什么被折叠?



