lua-users home
lua-l archive

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


On Wed, Aug 3, 2011 at 12:11 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Wed, Aug 3, 2011 at 9:08 AM, STPeters <stefan@chehalispost.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?

wes