lua-users home
lua-l archive

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


Use multiple returns...

function CreateSprite()
   ...
   return sp, sp
end

local sp
self.spBackGround, sp = CreateSprite()


Or...

function f(p)
   return p, p
end

local sp
self.spBackGround, sp = f(CreateSprite())



Or perhaps something a little different... Have each of your sprite's methods return its first argument...

self.spBackGround = CreateSprite()
local sp = self.spBackGround:setSize( 10, 10 ):doSomething()
sp:doSomethingElse()


Mike



Leigh McRae wrote:
Hi all,
I find myself repeating the same type of code over and over. Is there an idiom for this type of thing? self.spBackGround = CreateSprite() local sp = self.spBackGround
sp:setSize( 10, 10 )
I am looking for something along the lines of: local sp = self.spBackGround = CreateSprite()
sp:setSize( 10, 10 )
Leigh McRae