lua-users home
lua-l archive

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


It was thus said that the Great Andrew Starks once stated:
> 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

x = {}
print(something(x[1]))
--true, good (I assume)
print(something(x.foo))
--true, good (I assume)

  Interesting.  I think what's happening here is that during compilation,
Lua realizes that foo does not exist as a global variable, and thus, does
not generate a load statement for the paramter to something() (that would be
my guess, given the behavior).

  But my intent with

	something(mary) --[[ something about mary ]] end

is that, *as given* (with a formal parameter) there is no way for something
to determine if something was passed.  It can if you change the formal
paramter to a vararg.

  -spc