lua-users home
lua-l archive

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


>From lua-l@tecgraf.puc-rio.br  Fri Jun 16 23:52:12 2000
>From: Andy Tai <andy@exp.com>

>I would like to share some Lua variables or tables across multiple interpreters

This cannot be done directly, but it can be simulated:

1. create a special state to hold shared global variables.
2. setup "getglobal" and "setglobal" tag methods in each other state
   to redirect globals to the state created in 1.
   see the FAQ for how to do this (see the read-only variables section)
   or see test/trace-globals.lua. See also the lua-l archives.
   However, these tag methods have to be written in C, because they deal
   with multiple states.

Also, this scheme only works easily for simple values (numbers, strings,
and userdata, perhaps). For tables, you'd have to copy each field.

I haven't tried this, but I'd like to know how it works for you.
--lhf