[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Sharing objects between states
- From: Wesley Smith <wesley.hoke@...>
- Date: Wed, 3 Aug 2011 00:19:44 -0700
On Wed, Aug 3, 2011 at 12:11 AM, steve donovan
> On Wed, Aug 3, 2011 at 9:08 AM, STPeters <email@example.com> wrote:
>> Can an object be created in one Lua state, passed to C++, and then passed to
>> a script running in a different Lua state?
> The short answer is no, not if these are separate Lua 'universes' (not
> different coroutine states).
Actually, I think the answer is of course, you can do anything but you
have to manage the complexity. He's not asking if you can pass
objects from one lua_State to another from within the lua_State, which
is clearly not possible without some kind of C-side functions that
enable such functionality. Instead, he's asking if objects created by
one lua_State can be shoved into another through C++. As long as you
have a list of such pointers somewhere, there's nothing preventing you
from pushing them into any number of other states. The only
complication is that if such pointers get garbage collected and you
don't have a ref counting mechanism is place, you're likely to run in
to trouble. If you add multi-threading, you're adding even more
complexity, particularly if the objects are still in the creation
state when they're being used in a state in another thread.
I think the better question to ask is why you would want to do this.
What's the motivation?