lua-users home
lua-l archive

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


> Now understand that what I want to do is to make Lua's GC work also
> with the following code:
>
> --------------
> a = fxline(sin, 0, 2*pi) -- create a line
> b = plot('Test plot')
> -- add the line a to plot b as a dashed line
> b:addline(a, 'red', {{'dash', 7,3,3,3}})
> b:show()
> --------------
>
> What's wrong about that ?

Nothing at all!

> Clear enough ?

I'm getting there :)

Let me go line by line and see if I understand:



a = fxline(sin, 0, 2*pi) -- create a line
> have a line that is independent

b = plot('Test plot')
> have a plot that is independent

-- add the line a to plot b as a dashed line
b:addline(a, 'red', {{'dash', 7,3,3,3}})
> Does b, being a plot, keep a reference to the line, a, somewhere internally in it's C++ structures?  If so, a should either be added to b's environment table or reference counted.  If you're adding it to the env table, b should not try to use a when __gc is called or when it is freed IMHO

b:show()



Now that I see this code, it occurs to me that the design problem
you're facing is not unlike that of OpenGL with both client and server
code.  If I were doing this in OpenGL, line would be a buffer of
geometry data stored client side and dispatched to the server, which
copies the data internally for its own usage.  Of course with OpenGL,
you can also map memory and create objects that store such memory, but
these all clearly live on the server.  Perhaps this design strategy
could serve as inspiration for your project.

In the OpenGL bindings to textures, FBOs, vertex buffers, etc. that
I've written, large blocks of image and geometry data are passed
around with a generalized memory buffer that is reference counted.
All other objects use the memory buffers internally to pipe data
around but are themselves not reference counted.  I wonder if such a
design might help you here.  For example:


a = fxline(sin, 0, 2*pi) -- create a line
b = plot('Test plot')
-- add the line a to plot b as a dashed line
b:addline(a:data(), 'red', {{'dash', 7,3,3,3}}) -- use the data method
to get the geometry data
b:show()

wes