[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: tolua++ porting to 5.2
- From: Hadriel Kaplan <HKaplan@...>
- Date: Tue, 15 Jan 2013 06:37:00 +0000
On Jan 15, 2013, at 12:34 AM, William Ahern <william@25thandClement.com> wrote:
> Yeah, but these schemes are usually a bad idea. Scratch that--they're
> _always_ bad. It's far saner to just suck it up and add reference counting
> semantics to those C or C++ objects bound as userdata in Lua.
>
> That should be even easier in C++ than in C, although I'm not too familiar
> with C++. I would imagine that something like shared_ptr would be a sane
> prerequisite for an automatic C++ bindings generator.
Yeah, we use Lunar and and one of the changes we made to Lunar was to support ref counting as our 'solution' so far. The downside is that it hides the problem that the Lua code is actually broken/wrong. I mean if your application is mostly C-code, and just using Lua as a business-logic/scripting engine, there are plenty of cases where a C-object really is useless/stale/dead at some point only known by the C-side application code. Or worse it was dead and is now alive again for a different user. Like if the object represents some hardware component or resource, and never gets new/deleted but just assigned/unassigned from a pool. Of course you could use an intermediate/proxy C-object to handle that, but that's just moving the problem around.
Regardless, my guess is this is not a one-size-fits-all thing. Some folks can live with every object being ref-counted, others probably can't.
-hadriel