Transfering tables and variables across LUA states?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Transfering tables and variables across LUA states?

jdarling
Does anyone know if you can transfer (seamlessly) a variable or table
across LUA states?  Currently I have multiple states executing scripts
thoughout my application.  In some I have the need to have an almost
global feel to them, where one state would be modifying another states
variables.  The whole thing is not threaded (so no locking will be
necessary), and scripts are executed sequentially in an event like
system.

Any help would be greatly appriciated :)

 - Jeremy

"Help I suffer from the oxymoron Corporate Security."


Reply | Threaded
Open this post in threaded view
|

Re: Transfering tables and variables across LUA states?

Tomas-14
  Hi

> Does anyone know if you can transfer (seamlessly) a variable or table
> across LUA states?
  No.  But you can transfer some types of values using the C API.

> Currently I have multiple states executing scripts
> thoughout my application.  In some I have the need to have an almost
> global feel to them, where one state would be modifying another states
> variables.  The whole thing is not threaded (so no locking will be
> necessary), and scripts are executed sequentially in an event like
> system.
  Take a look at Rings library:

http://www.keplerproject.org/rings/

  Rings provides a function to create Lua states in Lua.  This
will create an object with a method called `dostring'.  This method
receives a piece of Lua code to be executed in the newly created state,
and can receive optional parameters, which will be stored in the `arg'
table (we'll release a version for Lua 5.1 very soon :-).

  Hope it helps,
  Tomas
Reply | Threaded
Open this post in threaded view
|

Re: Transfering tables and variables across LUA states?

Javier Guerra Giraldez
On Thursday 16 March 2006 10:32 am, Tomas wrote:
> > Does anyone know if you can transfer (seamlessly) a variable or table
> > across LUA states?
>
>   No.  But you can transfer some types of values using the C API.
>
....
>
>   Take a look at Rings library:
>
> http://www.keplerproject.org/rings/

unfortunately, it only copies primitive values, not tables.

a somewhat more complete solution would be to use Pluto
(http://luaforge.net/projects/pluto/), to mangle a complex structure into a
string and then transfer that.

a nice optimisation would be to add new writer/reader functions to Pluto that
do the inter-state transfer.  it still would be several copies, but might be
worth the try.

even better would be if lua_xmove() could work across separate states.  of
course the naive implementation would hopelessly confuse the two garbage
collectors.  maybe a full working interstate lua_xmove() would be as heavy as
Pluto...


--
Javier

attachment0 (207 bytes) Download Attachment