lua-users home
lua-l archive

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


On 04/07/2014 02:36 PM, Joachim Bürmann wrote:
Hello all,

I'm wondering if it is possible to share a 'global' lua table created in
C++ between two running Lua interpreter instances.

Both Lua interpreters are called alternately from C++ and execute the
same Lua script. A race condition while accessing the global table won't
happens.

I know how to create a table in C++ and pass it to the Lua interpreter.
But I'm unsure if Lua internally just hold it's own copy of the table
and therefore both interpreters access two different tables.
What I need is a single table to exchange informations between both
running interpreters.

Any hints or suggestions?

Thanks a lot

Joachim






Normally, you can't share a table (or other gc objects) between dirrent Lua `universe',
Each Lua global state has its own heep and gc, and Lua's C API doesn't expose gc objects
to outside the Lua core.

However, if you are ok to go beyond the API, you can of course access and play with the
internal data structures, _ON YOUR OWN RISK_.
That said, _never really do it_.


In your case, I suppose you'd better rethink your design. Since you don't need two Lua
interpreters to run concurrently, why the need to use two different Lua interpreters at
all? Can't you just use a single Lua interpreter and run your scripts in different
coroutines instead? Your application code then schedules the coroutines.