?????? Is there any possible way to copy one lua_state to another?

  • From: "??????" <stephenmax@xxxxxx>
  • To: "luajit" <luajit@xxxxxxxxxxxxx>
  • Date: Thu, 17 Sep 2015 17:19:11 +0800

Thank you,


this solution is good.
But those tables are just some game config data and lua module load from file,
it would be better to load them again than serialize-deserialize.
I wonder why lua lack functions like "lua_copystate".






------------------ ???????? ------------------
??????: "Nagaev Boris";<bnagaev@xxxxxxxxx>;
????????: 2015??9??17??(??????) ????4:23
??????: "luajit"<luajit@xxxxxxxxxxxxx>;

????: Re: Is there any possible way to copy one lua_state to another?



On Thu, Sep 17, 2015 at 11:14 AM, ?????? <stephenmax@xxxxxx> wrote:

Hi there,

Is there any possible way to copy one lua_state to another?
My application have several c thread, and each one of them need their own
lua_state.
They share same conf files, so each c thread need load the same lua files by
there own.
So can I let the first c thread establish the lua environment(such as global
tables), then just copy this lua_state (of course also copy global tables)
to remaining threads?
And I dose not want those lua_state to share same environment like
lua_newthread does.
I know this is not a luajit specific question, just think guys in here are
far more experienced :)

Hi,

if your tables use plain types for keys and values (boolean, string,
number, nested tables), you can serialize the table using JSON or YAML
and deserialize it in another Lua state. Lua has many JSON and YAML
implementations.

--


Best regards,
Boris Nagaev

Other related posts: