lua-users home
lua-l archive

Re: Assign idiom

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


Leigh McRae wrote:
> I am looking for something along the lines of:
> local sp = self.spBackGround = CreateSprite()
> sp:setSize( 10, 10 )
If setSize() returns the sprite, then:
 self.spBackGround = CreateSprite():setSize(10, 10)
It's hard to see a way to avoid a multiple assignment to capture to a
local variable. Perhaps:
 function dup(x) return x, x end
 local sp
 sp, self.spBackGround = dup(CreateSprite():setSize(10, 10))
Looks like that one was already suggested! You might also try:
 function self:set(k, v)
 self[k] = v
 return v
 end
 local sp = self:set('spBackGround', CreateSprite()):setSize(10,10)
I think your original code is easier to read.
Doug
-- 
Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220

AltStyle によって変換されたページ (->オリジナル) /