[英]Array as value in a lua table
I couldn't find an answer to my question: Can you have an array as value in a lua table? 我找不到我的问题的答案:lua表中可以包含数组作为值吗?
local colors = {"blue" = {0,0,1,1}, "green" = {0,1,0,1}, "red" = {1,0,0,1} , "orange" = {0.5, 0, 0.5, 1}, "black" = {0,0,0,1}, "gold" = {1, 215/255, 0, 1}}
I get the error on this line using the corona sdk: 我使用电晕SDK在这条线上收到错误:
'}' expected near '='
'}'预期在'='附近
It's tables all the way down :-) Yes, tables (including ones indexed like arrays) can be elements of tables in Lua. 它是所有的表:-)是的,表(包括像数组一样被索引的表)可以是Lua中表的元素。 This chapter in the Lua manual explains the different ways of defining the elements of a table.
Lua手册中的这一章介绍了定义表元素的不同方法。
In your example, you should not put quotation marks around the key. 在您的示例中,您不应在密钥周围加上引号。
local colors = { blue = { 0, 1, ...}, green = { ... }, ... }
Or you can do: 或者,您可以执行以下操作:
local colors = {}
colors[ "blue" ] = { 0, ... }
colors[ "green" ] = ...
Or 要么
colors.blue = { 0, .... }
colors.green = ....
The latter is syntactic sugar for the other forms. 后者是其他形式的语法糖 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.