rawset(tbl,name,())
and
rawset(tbl,name, function() end)
Rawset The function returns a table, so what does it mean to have a table or function to represent the value in the rawset function?
rawset (table, index, value)
: Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil, and value any Lua value.
What does this mean:
> The metatable of the table is not used: this is why it is a “raw” set, and the field is directly Added; without the original, the metatable of the table will be used to handle the “set” action; any value whose index is different from nil: In Lua, this actually means any type of Lua object except nil: Number, function, another table, etc. (Lua ref manual lists all types);
> value Any Lua value: Same as before, but can even be nil: If set to nil, it effectively deletes the item from the table .
So the index name only means that the table is an associative array (unless the name is a number, but this is misleading), in the first case, the associated value is another table, in the second In this case, it is a Lua function.
The rawset function in Lua is generally to pass the table, index and value, but I encountered this code:
< /p>
rawset(tbl,name,())
and
rawset(tbl,name, function() end)
The Rawset function returns a table, so what does it mean to have a table or function to represent the value in the rawset function?
Reference manual:
rawset (table, index, value)
: Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil, and value any Lua value.
What does this mean:
> The metatable of the table is not used: this is why it is a “raw” set, the field is added directly; without the original, the metatable of the table will be used Handle the “set” action; any value whose index is different from nil: In Lua, this actually means any type of Lua object other than nil: numbers, functions, another table, etc. (Lua ref manual List all types);
>Value Any Lua value: Same as before, but can even be nil: If set to nil, items are effectively deleted from the table.
So the index name is only Indicates that the table is an associative array (unless the name is a number, but this is misleading), in the first case, the associated value is another table, in the second case, it is a Lua function.