Lua多维表创建
我在 Lua 中有一个多维表,但我似乎无法创建它以便在 Lua 中使用?
桌子
items ::= {
{["category"]="tools", ["name"]="hammer", ["price"]=10, ["quantity"]=5 },
{["category"]="tools", ["name"]="saw", ["price"]=15, ["quantity"]=4 },
{["category"]="tools", ["name"]="screwdriver", ["price"]=4, ["quantity"]=12 },
{["category"]="tools", ["name"]="measuring tape", ["price"]=9, ["quantity"]=3 },
{["category"]="tools", ["name"]="pliers", ["price"]=10, ["quantity"]=5 },
{["category"]="tools", ["name"]="wrench", ["price"]=10, ["quantity"]=5 },
{["category"]="fasteners", ["name"]="nails", ["price"]=.1, ["quantity"]=1500 },
{["category"]="fasteners", ["name"]="screws", ["price"]=.2, ["quantity"]=1200 },
{["category"]="fasteners", ["name"]="staples", ["price"]=.05, ["quantity"]=2000 },
}
错误:<代码>'<名称>'期望靠近“:”
I have a Multidimensional table in Lua but I can't seem to create it to be able to use in Lua?
Table
items ::= {
{["category"]="tools", ["name"]="hammer", ["price"]=10, ["quantity"]=5 },
{["category"]="tools", ["name"]="saw", ["price"]=15, ["quantity"]=4 },
{["category"]="tools", ["name"]="screwdriver", ["price"]=4, ["quantity"]=12 },
{["category"]="tools", ["name"]="measuring tape", ["price"]=9, ["quantity"]=3 },
{["category"]="tools", ["name"]="pliers", ["price"]=10, ["quantity"]=5 },
{["category"]="tools", ["name"]="wrench", ["price"]=10, ["quantity"]=5 },
{["category"]="fasteners", ["name"]="nails", ["price"]=.1, ["quantity"]=1500 },
{["category"]="fasteners", ["name"]="screws", ["price"]=.2, ["quantity"]=1200 },
{["category"]="fasteners", ["name"]="staples", ["price"]=.05, ["quantity"]=2000 },
}
Error:
'<name>' expect near ':'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
::=
有点奇怪。看起来你正在做 ASN.1 而不是 Lua 。试试这个:
当我使用它时,我在 Lua shell 中得到以下内容:
That
::=
is a bit bizarre. It looks like you're doing ASN.1 instead of Lua there.Try this instead:
When I use that, I get the following in the Lua shell:
这是创建表格的一种方法。
Here's a way you could create tables.