lua-users home
lua-l archive

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


On Wed, Oct 18, 2000 at 01:24:29AM -0700, Eric Tetz wrote:
> ? I originally discovered that Lua discards all but the first return value of a function when used
> in an argument list (unless it's the last or only arg) by accident, when trying to do something
> like:
> 
>    drawtext (pos:xy(), text)
> 
> where xy() returns the x and y of a Point. 

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()")

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net