More on garbage collection

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

More on garbage collection

Alex Sandro Queiroz e Silva
Hallo,
	I'm using Lua as a description/shader language in a simple ray tracer
I'm writing. For instance, without the camera and light declarations a simple
scene could be:

BeginFrame(FB_PNG, "ball.png", 320, 240)

Sphere {
	radius = 1.0,
	colour = Blue,
	centre = Point { y = -3.0 }
}

EndFrame()

	Sphere is actually the function _sphere_ctor which creates and adds a
sphere to the scene created by the BeginFrame call. It doesn't return a
userdata (just like the above Point call ) to avoid it being garbage collected
by Lua. But now I intend to add CSG operations, and I would like the syntax to
be like:

BeginFrame(FB_PNG, "ball.png", 320, 240)

Union {
	Sphere {
		radius = 1.0,
		colour = Blue,
		centre = Point { y = -3.0 }
	}
}

EndFrame()

	And now clearly Sphere must return a value. Is there a easy way to
handle the two cases or I will have to create a reference to every primitive
created? Thanks in advance for any help.
	Cheers,

  --Alex	[hidden email]	http://www.lcg.dc.ufc.br/~asandro/
+-----------------------------------------------------------------------------+
|"Minha força vem da solidão. Não tenho medo das chuvas tempestuosas nem das  |
| grandes ventanias soltas, pois eu também sou o escuro da noite."            |
|	- Clarice Lispector                                                   |
+-----------------------------------------------------------------------------+