lua-users home
lua-l archive

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


Am 22.05.2014 04:57 schröbte Coda Highland:
On Wed, May 21, 2014 at 7:32 PM, Eric Wing <ewmailing@gmail.com> wrote:
I think this always works for the SDL case because you always need to
create the renderer first. But I have another library with a similar
problem (physics library) where you need to add bodies to the world.
The world doesn't like bodies being deleted out from under it simular
to the renderer case. But unfortunately, worlds can be created after
bodies (because bodies can be put in different worlds in this case).

Do you need those cases in your Lua code? Maybe you can design a Lua API where those situations can't happen ...


Thanks,
Eric

At this point, my personal recommendation would be to use tables
containing a lightuserdata, and maintain a C-side refcount independent
of the Lua refcount.

This sounds like manual resource management to me, but I can't imagine a situation where lightuserdata would solve an object lifetime problem anyway, so I might be missing something here.

But additional reference counting on the C side could be an idea ...

This has the additional advantage of simplifying
the task of mapping bodies returned from e.g. collision queries back
to Lua objects.

/s/ Adam


Philipp


p.s.: It's funny how different the approaches to binding C code are -- I wouldn't touch lightuserdata with a ten-foot pole, but I have no problems relying on finalization order. Apparently some people do the exact opposite ...