-- 默认整数索引
days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
print(days[4]) --> Wednesday
-- identifier索引
a = {x = 10, y = 20}
-- 空
a = {}; a.x = 10; a.y = 20 --长度不固定,因而较慢
-- 复合索引
polyline = {color="blue",
thickness=2,
npoints=4,
{x=0, y=0}, -- polyline[1]
{x=-10, y=0}, -- polyline[2]
{x=-10, y=1}, -- polyline[3]
{x=0, y=1} -- polyline[4]
}
-- 方括号通用索引(字符串不限于identifier)
opnames = {["+"] = "add", ["-"] = "sub", ["*"] = "mul", ["/"] = "div"}
a = {["x"] = 0, ["y"] = 0}
b = {[1] = "r", [2] = "g", [3] = "b"}
-- 最后一项后可以用逗号
a = {[1] = "red", [2] = "green", [3] = "blue",}