lua-users home
lua-l archive

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


This actually gets me thinking. I find I tend to think as a C coder in all the languages I use. So maybe I just need to put my lua hat on and figure out a way. The chaining is interesting but I tend to use sp to much, hence why I make it a local. Good food for thought though. I would have thought there would be something for this since lua uses tables for everything. I suspect lots of people do this kind of thing.

----- Original Message ----- From: "Rob Heyes" <rob@rheyes.co.uk>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, March 08, 2007 12:33 PM
Subject: Re: Assign idiom


Leigh McRae wrote:

Some people may frown on this, but your sprite's parameter setting methods could each return self
then you could use code like

self.spBackGround = CreateSprite():setSize(10, 10):setName('MySprite') etc.

Another possibility is to pass a table to CreateSprite with the values e.g.

self.spBackGround = CreateSprite({Width = 10, Height = 10, Name = 'MySprite'})

Yeah, I need sp after that. The pattern is that I create a sprite to be stored in 'self' and then configure sp with calls. Thanks anyways.

----- Original Message ----- From: "Luiz Henrique de Figueiredo" <lhf@tecgraf.puc-rio.br>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, March 08, 2007 12:09 PM
Subject: Re: Assign idiom


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

If you don't need sp after that, try
CreateSprite():setSize( 10, 10 )