[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Implementing __index to return nil?
- From: Coda Highland <chighland@...>
- Date: Thu, 14 Feb 2013 14:54:02 -0800
On Thu, Feb 14, 2013 at 2:51 PM, Marc Lepage <email@example.com> wrote:
> Should __index actually return nil if there is no value, or just not return
> any value?
> The reference manual pseudo code for __index shows an explicit return nil,
> so I'm guessing that's the proper way.
> Is there a subtle semantic difference? Can anyone provide examples of where
> this would make a difference?
> I am particularly interested in the C API case. So instead of return 0, it
> would be lua_pushnil(L) then return 1.
> If it did return 0, would that be bad for the stack? (Wouldn't most calls
> specify the number of results expected, and get nil anyways?)
> Just trying to understand subtleties here.
There's no difference. nil means no value. In terms of Lua code,
failing to return anything means that the function is treated as
returning nil. In the C API, it only makes a difference if you're
using MULTRET, at which point you should be counting the number of
return values anyway.