When, in lua, I run this code, the metavalue __index is nil
t = {__index = t}
print(t.__index)
--prints nil
but if I write it like this...
t = {}
t.__index = t
print(t.__index)
--prints table ****
... it works My question is why.
When, in lua, I run this code, the metavalue __index is nil
t = {__index = t}
print(t.__index)
--prints nil
but if I write it like this...
t = {}
t.__index = t
print(t.__index)
--prints table ****
... it works My question is why.
Copyright © 2021 Jogjafile Inc.
In
t = {__index = t}tis whatever you assigned totbefor that line. In your case you never assigend a value totsotis a nil value.This is basically equivalent to
As t is nil this is equivalent to
or
or
In the second snippet
you assign an empty table to
t. Sot.__index = tassigns that empty table tot.__indexSee Visibility Rules
Edit
t = {text = "hello"}is equivalent tohere you assign a string value. Not a nil value as in your first example.