gpt4 book ai didi

lua - 如何在初始化期间自引用表

转载 作者:行者123 更新时间:2023-12-04 14:11:11 25 4
gpt4 key购买 nike

有没有更短的方法来做到这一点:

local thisismytable = {
non = sequitur
}
thisismytable.whatismytable = thisismytable

任何帮助,将不胜感激。
我不想重新创建预先存在的功能。

最佳答案

不。

如果你能忍受这两种表达方式的区别 thisismytable:whatismytable()而不是 thisismytable.whatismytable ,你可以这样做:

local thisismytable = {
non = sequitur,
whatismytable = function (self) return self end
}

测试:
print(thisismytable)
print(thisismytable:whatismytable())

更多用法:
print(thisismytable:whatismytable().non)

关于lua - 如何在初始化期间自引用表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32539680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com