[英]How to use this LUA table?
I'am new to LUA and I'am using it to create some Envoy Filters. 我是LUA的新手,并且正在使用它来创建一些Envoy过滤器。 So, I have found a piece of code with a Table like this :
所以,我找到了一段带有这样的Table的代码:
MyClass = {
[":path"] = "something"
}
I want to add a contructor to MyClass, so I do this : 我想向MyClass添加构造函数,所以我这样做:
function MyObject:new (o, path)
o = o or {}
setmetatable(o, self)
self.__index = self
self.path = path -- Here is the problem
return o
end
So, my problem is : How can I access to the [":path"] variable in my contructor to assign a value? 因此,我的问题是:如何访问构造器中的[“:path”]变量以分配值?
self.path
does not work self.path
不起作用
self.:path
does not work self.:path
不起作用
self.[":path"]
does not work self.[":path"]
不起作用
This syntax [":foo"] is something I have found nowhere else than in my Envoy sample filter. 这种语法[“:foo”]是我在Envoy示例过滤器中找不到的。
Thank you for your help 谢谢您的帮助
The dot notation is a syntactic sugar for a complete form. 点符号是完整形式的语法糖。
table.name
is equivalent to table["name"]
. table.name
等效于table["name"]
。 So in your case it should be self[":path"]
因此,在您的情况下,它应该是
self[":path"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.