Is there a shorter way to do this:
local thisismytable = {
non = sequitur
}
thisismytable.whatismytable = thisismytable
Any help would be appreciated. I don't want to re-create pre-existing functionality.
Is there a shorter way to do this:
local thisismytable = {
non = sequitur
}
thisismytable.whatismytable = thisismytable
Any help would be appreciated. I don't want to re-create pre-existing functionality.
No.
If you can stand the difference between these two expressions thisismytable:whatismytable()
instead of thisismytable.whatismytable
, you could do:
local thisismytable = {
non = sequitur,
whatismytable = function (self) return self end
}
Testing:
print(thisismytable)
print(thisismytable:whatismytable())
More usage:
print(thisismytable:whatismytable().non)
:
just sends the accessed table as first argument to called function - it's just a wrapper around your attempt with function overhead. –
Ingrained You can't. I use a helper function.
local function ref(t)
for k, v in next, t do
if v == ref then t[k] = t end
end
return t
end
local root = ref{left=ref, right=ref}
assert(root.left == root)
© 2022 - 2024 — McMap. All rights reserved.