分别找到这2句代码:

 
复制代码
  1. cc(self):addComponent("components.behavior.EventProtocol"):exportMethods()
  2. cc.GameObject.extend(self):addComponent("components.behavior.EventProtocol"):exportMethods()


所以 cc(self) 就等于调用 cc.GameObject.extend(self) 。

----------------------------------------------------------------------------
原因是因为再 framework/cc/init.lua 中有这样一段定义:

 
复制代码
  1. cc.GameObject = import(".GameObject")
  2. local GameObject = cc.GameObject
  3. local ccmt = {}
  4. ccmt.__call = function(self, target)
  5.     if target then
  6.         return GameObject.extend(target)
  7.     end
  8.     printError("cc() - invalid target")
  9. end
  10. setmetatable(cc, ccmt)



这段代码定义了 cc() 的执行行为,也就是 __call 的调用效果。

Ps:如果不知道 __call 什么意思的可以看一下这里的解释
[lua] __call metamethod的用处 

相关文章:

  • 2021-12-04
  • 2021-12-19
  • 2021-11-17
  • 2021-11-19
  • 2021-12-02
  • 2021-12-08
  • 2021-08-01
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-05-07
  • 2021-12-24
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案