lua-users home
lua-l archive

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




On 2017-07-13 09:47 AM, Luiz Henrique de Figueiredo wrote:
I'm not allowing v to be omitted, I'm allowing t to be omitted.
Yes, I meant t, sorry for the typo.

Allowing t to be omitted is confusing because it is in the interest of
the programmer to be explicit about what metatable is being set.

setmetatable(v) is not explicit and seems very confusing to me.

Of course, if you are fine with this, use your patch.
But you don't need to patch the C code. You can it in Lua:

	local old_setmetatable=setmetatable
	function setmetatable(v,t) return old_setmetatable(v,t) end

The code seems useless but the explict argument t implies that it gets
an explict nil if you call setmetatable(v).


It doesn't feel confusing to me. Both setmetatable({}) and rawset({}, 1) feel natural as "unset" operations. (but I can accept that neither are supported and argue for their support without being completely rude about it.)

setmetatable(v) with omitted t is like telling it to unset. Other ppl might expect it to set a new, empty metatable, but the nil/none semantics of lua (see e.g. load()) tend towards unsetting.

(I'd also argue setmetatable should return 2 values: the table, and the new metatable. that is, both arguments passed to it.)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.