lua-users home
lua-l archive

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


On Mon, Sep 12, 2011 at 09:17:56AM +0200, Enrico Colombini wrote:
> On 12/09/2011 8.17, Dirk Laurie wrote:
> > In both cases, the behaviour seems not to be planned for, but
> > not sufficiently obnoxious to justify testing for it.
> 
> Speaking of testing (nothing new here):
> 
>   type(f()) --> stdin:1: bad argument #1 to 'type' (value expected)
>   type(g()) --> nil

It is clear that at the level of the C API, there is a difference
between a stack of length 1 containing a nil and a stack of length
0.  The Lua libraries are written in C and make use of the C API.

The documentation of lua_CFunction says: 

    To return values to Lua, a C function just pushes them onto the 
    stack, in direct order (the first result is pushed first), and 
    returns the number of results.

>From this, it seems that it is not an implementation detail that
`return` and just reaching `end` do the same, which is different
from `return nil`, which is different from `return nil,nil` etc.
It is fundamental to the way the stack and C API works.

That does not change my opinion that it is bad design to rely on
the difference between `return` and `return nil`, 

Dirk