lua-users home
lua-l archive

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


On Thu, Jul 13, 2017 at 6:12 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> I hope you do not expect that the previous sentence ("Parameters act as local variables that are initialized with the argument values") applies also to C functions.

In fact, at some point back in the past, that is exactly what I expected. I expected that an omitted argument would be seen as nil in a C function. I learned the actual behaviour only when I had to chase some subtle bugs introduced by my expectation. I did not like the experience. That is why I called that arcane and confusing.

Another problem is that your language above implies that we somehow must expect that setmetatable should behave like a "C function" and not a like a Lua function. Why? I do not think "because it is implemented in C is a sensible answer for someone who has no idea about the implementation of Lua. And why, indeed, should we expect that C functions behave differently? The difference is explained very compactly at the end of section 4.3, but it only makes sense for a C programmer, not for a Lua programmer (a pure Lua programmer would not even look there), who still sees there "virtual type LUA_TNONE, which behaves like a nil value". Does that imply that every user of Lua should understand the arcane details of Lua's C language API? I think that would be too much to expect.

> Similarly for the next sentence ("A vararg function [...] collects all extra arguments and supplies them to the function through a vararg _expression_").  So, I see no reason to expect that this particular sentence would apply to C functions.

In fact, the behaviour of C functions can be most easily understood by assuming they are always vararg. Even then the TNONE/TNIL difference remains, but at least the "adjustment" is taken out.

Cheers,
V.