lua-users home
lua-l archive

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


On Thu, Jul 13, 2017 at 5:28 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:

> The authoritative answer is given by the manual which says

>         setmetatable (table, metatable)
>         http://www.lua.org/manual/5.3/manual.html#pdf-setmetatable

> Note that the second argument must be present. It is not marked as optional.

This semantics is incompatible with section 3.4.11, which says:

When a function is called, the list of arguments is adjusted to the length of the list of parameters, unless the function is a vararg function, which is indicated by three dots ('...') at the end of its parameter list.

Several lines further in the text, we have an example:

     function f(a, b) end
[...]
     CALL            PARAMETERS
     
     f(3)             a=3, b=nil
This, per the manual, a non-vararg argument, if omitted, is nil. This implies that the call setmetatable(t), which is not vararg, shall be equivalent to setmetabable(t, nil), which has a specified meaning.

I should say that the TNONE vs TNIL difference is very arcane and confusing. And this difference only exists for C functions, and one can make a C function conform with the documented behaviour (3.4.11), or not.

Cheers,
V.