lua-users home
lua-l archive

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

Hello yall,

I'm developing a multithread system, a server answering to a lot of connections at the same time. I'm using Lua to easier the job of having custom made versions. Everything is in C++ and I'm using Luna.h.

Now I'm at the point of choosing how I will use multi thread with Lua. For now I implemented a lua pool (no queues yet) that gives me an already initialized lua_State* whenever I need one. So, I open a new thread (using PThreads on Linux), get an unused lua_State* from the pool, send the inputs, run the script and get the results back. But this model has 2 problems to me:
1 - Scope pollution: and second time I run the script with the same lua_State* from the pool, the global variables set by the first run are still there. Is there a fast way to clean only the variables set by the Lua script?
2 - Global variables are not global anymore. One script doesn't have access to the global variables set by another instances. On thread doesn't talk to the other using lua entities: numbers, tables, etc...

I only need a solution to one of the items, the second preferentially.

But, maybe this model is not good at all. What are you using to solve the multi thread problem?

Thank you all in advice!

Best regards,
Daniel Colchete