lua-users home
lua-l archive

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


I would start by installing a custom allocator into Lua that would serve as a suballocator for common object types. That should make the cost to allocate and free your vector objects cheap. That still leaves the need to construct them -- i.e., set their metatable, etc -- but at least you won't be fighting with your allocator.

You could also add new methods such as AddVectorXYZ and change your example to:

	function sprite.foo( self )
		self.position:AddVectorXYZ( 1, 2, 3 )
	end

I take it that AddVector was already modifying its receiver rather than simply adding two vectors and returning a third. If it doesn't do so, then consider adding versions that do and that return themselves. Then you can write chaining code like the following:

self.postion:OffsetByXYZ( -xcenter, -ycenter, - zcenter ):RotateByXYZ( 12, 5, 4 ):OffsetByXYZ( xcenter, ycenter, zcenter )

Mark