[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: documentation: metatable is a reference (refman is unclear)
- From: nobody <nobody+lua-list@...>
- Date: Sun, 7 May 2017 12:02:52 +0200
Hey *,
(unless I fail at searching), the reference manual does not explicitly
state that metatables are "stored" by reference. (I.e. `setmetatable`
doesn't copy the thing passed as metatable, but puts a reference to it
in a suitable location.)
The closest thing to information on this is the next-to-last paragraph
of §2.1:
"Tables, [...] are objects: variables do not actually contain these
values, only references to them. Assignment, parameter passing, and
function returns always manipulate references to such values; these
operations do not imply any kind of copy."
While it's clear from this that `setmetatable` receives a reference to
the (soon-to-be) metatable, `setmetatable` could do anything with that
(keep the reference, create a copy, …) To someone who knows Lua, it's
clear that it just stores the reference (simplicity and all that), but
§2.4 (Metatables and Metamethods) completely avoids the topic, and the
description for `setmetatable` and `lua_setmetatable` just states that
they "set" the metatable.
Should this be clarified? (Judging from a recent question on SO, this
has the potential to confuse some people coming from other languages.)
-- nobody