lua-users home
lua-l archive

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


This does not work though. Your version of something will always
report something, unless something is called:

function something(...)
        if select('#',...) == 0 then
            return false
        else
            local mary = ...
            return true
        end
    end

print(something())
--false, good

local baz
print(something(baz))
--true, good

print(something(foo))
--true, bad

On Wed, Jul 3, 2013 at 11:53 AM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
> On Wed, Jul 3, 2013 at 6:20 PM, Sean Conner <sean@conman.org> wrote:
>>
>>         function something(mary) --[[ something about mary ]] end
>>
>>   In straight Lua, there is no way for something to know if it was called
>> like:
>>
>>         something()
>>
>> or
>>
>>         something(nil)
>
>     function something(...)
>         if select('#',...) == 0 then
>             -- something about nothing
>         else
>             local mary = ...
>             -- something about mary
>         end
>     end
>
> That being said, it is not concise.
>
> -- Pierre-Yves
>