函数 – 之间的差异 和:在Lua

我困惑的函数调用via之间的区别。并通过:
> x = {foo = function(a,b) return a end,bar = function(a,b) return b end,}
> return x.foo(3,4)
3
> return x.bar(3,4)
4
> return x:foo(3,4)
table: 0x10a120
> return x:bar(3,4)
3

什么是:做什么?

解决方法

冒号用于实现将self作为第一个参数的方法。所以x:bar(3,4)应该与x.bar(x,3,4)相同。

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...