从 table 到另一个 table 的索引值
Index values from table into another table
我想通过选择一个 table 的键到另一个 table 来存储值,例如:
polyline = {color="blue", thickness=2, npoints=4}
stuff = {"polyline.color":[polyline.thickness]}
print(stuff)
应该产生:
blue 2
但是,我收到以下错误:
input:3: '}' expected near ':'
我相信,您混入了一些 Python 语法。您是否注意到使用两种不同的(错误的)方法来访问值?
我想,这就是您的 Lua 代码片段的意思:
polyline = {color = "blue", thickness = 2, npoints = 4}
stuff = {[polyline.color] = polyline.thickness}
for key, val in pairs(stuff) do
print(key, val)
end
local polyline = {color="blue", thickness=2, npoints=4}
local stuff = {polyline.color, polyline.thickness}
print(table.unpack(stuff))
我想通过选择一个 table 的键到另一个 table 来存储值,例如:
polyline = {color="blue", thickness=2, npoints=4}
stuff = {"polyline.color":[polyline.thickness]}
print(stuff)
应该产生:
blue 2
但是,我收到以下错误:
input:3: '}' expected near ':'
我相信,您混入了一些 Python 语法。您是否注意到使用两种不同的(错误的)方法来访问值?
我想,这就是您的 Lua 代码片段的意思:
polyline = {color = "blue", thickness = 2, npoints = 4}
stuff = {[polyline.color] = polyline.thickness}
for key, val in pairs(stuff) do
print(key, val)
end
local polyline = {color="blue", thickness=2, npoints=4}
local stuff = {polyline.color, polyline.thickness}
print(table.unpack(stuff))