lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

The docs are inconsistent about whether or not debug.setmetatable can
set the metatable of a non-table.  Currently, the docs say:

----

http://www.lua.org/manual/5.3/manual.html#2.4

2.4 – Metatables and Metamethods
[...]
You can replace the metatable of tables using the setmetatable
function. You cannot change the metatable of other types from Lua code
(except by using the debug library (§6.10)); you must use the C API
for that.


http://www.lua.org/manual/5.3/manual.html#pdf-setmetatable

setmetatable (table, metatable)
Sets the metatable for the given table. (You cannot change the
metatable of other types from Lua, only from C.)


http://www.lua.org/manual/5.3/manual.html#pdf-debug.setmetatable

debug.setmetatable (value, table)
Sets the metatable for the given value to the given table (which can
be nil). Returns value.

----

To improve clarity, I would rewrite the first as:

2.4 – Metatables and Metamethods
[...]
You can set or change the metatable of tables (but not other types)
using the setmetatable function.  To change the metatable of other
types, use debug.setmetatable (§6.10) or the C API.

I would rewrite the second as:

setmetatable (table, metatable)
Sets the metatable for the given table.  (To change the metatable of
other types, use debug.setmetatable (§6.10) or the C API.)


Cheers,

Parke