lua-users home
lua-l archive

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


Is it a candidate for use of __index and __newindex to set defaults?

On 9/19/06, Grellier, Thierry <t-grellier@ti.com > wrote:

Hello,

 

A quick search didn't gave me much hints on this. But I guess it must have already discussed…

my understanding is that this is not part of the Lua grammar. Hence one shall write something like:

 

function f(a, b, c)

  a = a or my_default_a

  b = b or my_default_b

  c = c or my_default_c

end

 

So this is possible to obtain what we want, although a little verbose. I'm however thinking of a syntax sugar like that:

 

function f(a or my_default_a, b or my_default_b, c or my_default_c)

end

 

Would it be too expensive or unlikely to add this to the language?

I understand that one might judge it error prone when calling a function with the false assumption that gaps will be filled. But I guess a kind of lua lint could be used to track this. And well anyway this problem is already here…

 




--
Bruce O. Benson, mailto:bbenson@gmail.com | http://www.tux.org
Donating spare CPU to science: Folding@home Team Debian (#2019)