将函数分配给变量或 table 时的不同行为

Different behavior when assigning a function to a variable or a table

我在 table 和带有函数的简单变量赋值之间有不同的行为。例如分配号码时不存在这种差异。

-- works fine
arrNum={1234}
Num=arrNum[1] -- Num=1234
arrNum[2]=arrNum[1] -- arrNum={1234,1234}

--does not work fine
arrFunc={function(x) return 10*x end}
func=arrFunc[1] -- func=function(x) return 10*x end
arrFunc[2]=arrFunc[1] -- arrFunc={function(x) return 10*x end,nil}

func 是函数(x) return 10*x 结束 但 : 我得到 arrFunc={function(x) return 10*x end,nil} 而不是 arrFunc={function(x) return 10*x end, 函数(x) return 10*x 结束}

我不明白这种区别,因为对我来说 func 和 arrFunc[2] 接收数据的 "box" 是一样的,包括 first-class 函数。

可能是一个线索(我没听懂):在控制台中,在最后一行执行后,我有以下信息:

arrFunc

{function() --[[..skipped..]] end --[[function: 0x90d7d0]], nil --[[ref]]} --[[table: 0x93afc0]] --[[incomplete output with shared/self-references skipped]]

事实上这个问题与 lua 无关,但似乎是 IDE.

的人为因素

我的 ZeroBrane 控制台的显示和 on-site 评论似乎是错误的。当我执行程序时,一切运行正常。