lua-users home
lua-l archive

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


On Wednesday 12 January 2011 04:42:18 steve donovan wrote:
> On Wed, Jan 12, 2011 at 11:37 AM, Steve Litt <slitt@troubleshooters.com> 
wrote:
> > So I guess I abused closures, huh?  :-)
> 
> It's a fine use of them, and I think the efficiency consideration only
> applies when there's lots of objects (as the greats of computing say,
> measure first, optimize next).
> 
> But it's wise to tell users about this dot business ;) [1]

Hey Steve, on a more serious note, how do you do your Lua OOP?

I've been doing

Point = {}

function Point.new(xa, ya)
	self={}

	--# CHARACTERISTICS
	local x = xa
	local y = ya
	local otherproperty

	--# GETTERS
	self.getx() return x end
	self.gety() return y end
	self.getotherproperty() return otherproperty end

	--# SETTERS
	self.setx(arg) x = arg end
	self.sety(arg) y = arg end
	self.setotherproperty(arg) otherproperty = arg end

	-- # OTHER "METHODS" GO HERE
end

mypoint = Point.new(2, 1)
yourpoint = Point.new(5, 2)
gettothepoint = Point.new(0,0)
mypoint.setx(3)
	
How do you do it?

Thanks

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt