lua-users home
lua-l archive

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


On 12/15/2012 7:39 AM, Jay Carlson wrote:

That link is a non-sequitur.


It was. Apologies. Thought I'd said more about the specific problems I'd had, rather than just talking about what I was doing instead.

The problems I was having concerned object lifetime. The conclusion I came to was that you couldn't safely use tolua's ability to bind values to C/C++ objects in a long-running app. Using tolua, if you have a USERDATA, you can say:

toluaUSERDATA.foo = 1

...and it adds that value to a table associated with the USERDATA.

The problem comes when the object has been destroyed in C/C++, and then another new object is created at the same address, and then later that object is imported into Lua before the previous reference is released; it makes the assumption that same address==same object, and so the object ends up with a bunch of bogus values attached to it, which (in my case) could cause crashes that were insanely difficult to diagnose.

You could use tolua safely in a short-lived tool that basically never destroys objects in C/C++ until it's about to exit. But even then, the project has basically been abandoned (the "contact us!" email link in the docs is dead), and I felt the code was ... not of the highest quality.

So, in short, I do not recommend anyone use tolua or tolua++. What I really need to do is finish up the docs I started for Dub; it's an awesome binding generator, but I have a hard time recommending IT because the learning curve is so steep. I use it now, though, and once you get it working, it's awesome.

Tim