嵌套表语法中对象的功能是什么?

我得到了一个像这样的表格,给了我一个"(" 在 't' 附近的错误提示:"errorline"。

这意味着必须有一个语法错误,但我无法检测出错误。你有任何想法,这个语法有什么问题吗?

t = {}

t[x] = {
   some = "data",

   foo = function() return "bar" end,

   elements = {   -- 这个类工作 100%,已经在几个项目中使用过。
     mon =  class:new(param),
     tue =  class:new(param2),
     n   =  class:new(param3),
   },

   function t[x].elements.mon:clicked()   -- <<< --- ERRORLINE
      --做一些事情
   end,
}
点赞
用户1137788
用户1137788

将函数 t[x].elements.mon:clicked() 在表声明之后 添加,即在表的右花括号之后。

t = {}

t[x] = {
   some = "data",

   foo = function() return "bar" end,

   elements = {   -- 这个类百分之百有效,已经用于几个项目。
     mon =  class:new(param),
     tue =  class:new(param2),
     n   =  class:new(param3),
   }
}

t[x].elements.mon.clicked = function(self)
      --dosomething
end

编辑:

正如评论中所提到的函数t[x].elements.mon:clicked()不起作用。 函数声明应该是t[x].elements.mon.clicked = function(self)

请注意,如果使用冒号调用一个点函数,第一个参数应该是 self 。即如果您将函数调用为 c = t[x].elements.mon:clicked(a,b),那么函数应该是 t[x].elements.mon.clicked = function(self,a,b)

2014-10-29 09:44:19