lua-users home
lua-l archive

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


On Mon, Apr 20, 2015 at 4:54 PM, Jan Behrens
<jbe-lua-l@public-software-group.org> wrote:
> Hi,
>
> With "none" I meant the absence of a value. There is no value "none",
> I'm sorry if I caused any confusion. However, in the C-API there is a
> constant LUA_TNONE (in addition to LUA_TNIL, LUA_TBOOLEAN, etc.) to
> distinguish between "no value at the given stack position" and "nil at
> the given stack position".
>
> I hope this clarifies my usage of the term "none".
>
> Regards,
> Jan
>
>
> On Mon, 20 Apr 2015 15:24:45 +0200
> Robert Virding <rvirding@gmail.com> wrote:
>
>> Where does 'none' come from? I cannot find any mention of it in the
>> 5.2 manual.
>>
>> Robert
>>
>>
>> On 19 April 2015 at 00:19, Andrew Starks <andrew.starks@trms.com>
>> wrote:
>>
>> >
>> >
>> > On Saturday, April 18, 2015, Jan Behrens <
>> > jbe-lua-l@public-software-group.org> wrote:
>> >
>> >> [...]
>> >>
>> >> Generally "nil" and "none" (none = no value) are distinct when you
>> >> call a function or return from a function. However, "none" gets
>> >> implicitly converted to "nil" if you store it in a variable (or
>> >> table) or if you put parenthesis around it (or use it in an
>> >> expression where a single value is expected).
>> >>
>> >> [...]
>> >> [...] You can use "select" to write your own functions to
>> >> distinguish between "nil" and "none":
>> >>
>> >> function test(...)
>> >>   if select("#", ...) == 0 then
>> >>     return "no value given"
>> >>   elseif ... == nil then
>> >>     return "nil value given"
>> >>   else
>> >>     return "non-nil value given"
>> >>   end
>> >> end
>> >>
>> >> [...]
>> >>
>> >> If you store a return value in a local variable or table, then
>> >> "none" always gets automatically converted to "nil". [...]
>

It pretty much amounts to: the stack is its own type of object: an
array of values with an explicit length. It's able to contain nil
values. Portions of it are exposed by the ... operator in Lua.

-- 
Sent from my Game Boy.