lua-users home
lua-l archive

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


Actually I think your last one is really good. I was also thinking of the multi-return idea but some of the code comes from C++ bindings. So W_TextRegion() is a wrapper for my C++ class. I didn't really want to change all my C++ code to suit lua.

 self.spName = W_TextRegion()

local sp = self.spName
sp:autoSize()
sp:setJustify( W_TextObject_Left )
sp:setFont( UI_Fonts.Comic_18 )
sp:anchor( W_Region_TopLeft, W_Region_TopLeft, self:getRegion( W_Region_Center ) )
self:addRegion( "FOREGROUND", sp )

 So I could the following:

function SetIdiom(tb, v)
   tb = v
   return v
end

local sp = SetIdiom( self.spBackGround, W_TextRegion() )

 Not bad, little hard on the eyes :)

----- Original Message ----- From: "Doug Rogers" <rogers@innocon.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, March 08, 2007 12:58 PM
Subject: Re: Assign idiom


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