Key为字符串
Key为整形
Key为字符串
-- 定义一个key,value形式的table
local kv = {fruit = "apple",
bread = "french",
drink = "milk"}
--通过key从table中取值
print(kv["fruit"])
-- Also works
print(kv.bread)
for index, value in pairs(kv) do
print("index:", index, "value:", value)
end
输出结果如下:
apple
french
index: fruit value: apple
index: drink value: milk
index: bread value: french
Key为整形
local tb = { [3] = "lang", [4] = "zhi", [5] = "cheng", [7] = "jing", [8] = "hong" }
print(tb[2],tb[8])
输出结果如下:
nil hong
本文出自赵青青,原文链接:http://www.cnblogs.com/zhaoqingqing/p/7684072.html,如需转载请自行联系原作者