Clone lua state

Recently, I have encountered many difficulties when developing using C ++ and Lua. My situation: for some reason, there may be thousands of Lua states in my C ++ program. But these states should be the same immediately after initialization. Of course, I can execute luaL_loadlibs () and lua_loadfile () for each state, but this is pretty hard (actually for me quite a long time even for the initial state). So, I'm interested in the following scheme: is it possible to save a separate Lua state (the only state that needs to be initialized), which is then cloned for other Lua states?

+3
source share
4 answers

When I started with Lua, like you, I wrote a program with thousands of states, had the same problem and thoughts, until I realized that I was doing this completely wrong :)

Lua has coroutines and threads, you need to use these functions to do what you need. They may be a little complicated at first, but you should understand them in a few days, it will be well worth your time.

+4
source

Unfortunately no.

You can try Pluto to serialize a fortune. It works very well, but in most cases it costs about the same time as regular initialization.

+1
source

API lua. , , .

lua_State *lua_newthread (lua_State *L);

, lua_State, . , , , .

. , Lua.

+1

, , , , . , , .

, . , .

, , , , , , : http://en.wikipedia.org/wiki/Fork_(operating_system)

- Lua, - : - lua?

0

Source: https://habr.com/ru/post/1738125/


All Articles