问题描述
我正在尝试向表/数组/列表中添加一个值(我仍然不确定lua的限制在哪里)。
我知道我可以执行以下操作,并且可以正常工作
local argumentList = {};
table.insert(argumentList,'hello I'm the first value0);
但是可以执行以下操作吗?
local argumentList = {};
argumentList:insert('hello I'm the first value0);
如果可能的话不必更改元表,因为我正在学习制作和哇的附加组件,它不允许这样做。 (或者更好的说我还没做到)
解决方法
是的,您可以这样做,但是您需要使用冒号:
argumentList:insert('hello I'm the first value0);
这是因为对于冒号,我们向Lua指示对象是self
class.method(self,params)
等于:
object:method(params)
在这种情况下,self
已经在收集object
作为值,因此不需要将其作为参数传递