lua-users home
lua-l archive

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


--- David Jeske <jeske@chat.net> wrote:
> Interesting. This is a very python-esq concept. In Python, multiple
> return arguments are tuples, and they are conceptually
> interchangable. In Python you could do:
> 
> class Position:
>   def __init__(self,x,y):
>     self.x = x
>     self.y = y
>   def xy(self):
>     return (self.x,self.y)
> 
> pos = Position(4,5)
> a_point = pos.xy()       # pso = (4,5)
> x,y = a_point            # x = 4, y = 5
> 
> x,y = pos.xy()           # x = 4, y = 5
> 
> Then, with drawtext, you could do:
> 
> def drawtext((x,y), text):
>   # do some work to draw your text
> 
> 
> drawtext((2,3), "draw some text at 2,3")
> drawtext(a_point,"draw some text at a_point")
> drawtext(pos.xy(),"draw some text at pos.xy()")

I really like that usage.  I like being able to code drawtext as:

  drawtext(int,int,string)

which is more flexible interface than

   drawtext(point,string)

and still being able to call it as

  drawtext(p:xy(),s)
  
Or being able to do say something succinct like

  drawrect(r:bounds(),clr:rgb())

instead of

  drawrect(r.tl.x, r.tl.y, r.br.x, r.br.y, clr.r, clr.g, clr.b).
   
To bad. :(

Apparently Lua's doesn't allow this because:
   A) it's easier to implement if you discard values
   B) it would be confusing when used with functions that don't always return the same number of
values

Personally I would rather have all return values used all the time.  Potential confusion could be
avoided with a little discipline (as with other Lua features), and you would really be able to
*use* this unique feature of Lua.
   
Cheers,
Eric

__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf!  It's FREE.
http://im.yahoo.com/