I have a lot of lua-script with the same name used for function name (intended for “entry point”) and I want to run them. But I want to make it as fast as possible.
After some browsing/googling/thinking I’ve got two solution.
1., I have a main lua_State. I load the all necessary given and my own libs/functions “into” it. Next I lua_dump() the current lua-script’s lua_State’s function (with using linked list for chunck container), then I lua_load() it to the main lua_State and then lua_call() the main lua_State. With this solution I don’t have to load all the libs for all the scripts. So the main lua_State is an “environment”. 🙂
2., I simply do the libs loading for all lua_State. And then lua_call() them.
The question would be that: Is even the first one logical correct? And if yes, which one would you use? Is there a better solution?
Thanks ahead and sorry for my English.
(And if the first one is really correct, are there some oblivious optimization possibility?)
As you put it, I don’t see why you’d want more than 1 Lua state. If you have only one Lua state all overhead you’ll have is loading the libs (once) and then loading the functions from the scripts you run (once, unless you need to ‘refresh’ them from the file). So simply have 1 state, and
dofilethe scripts.If you really need those multiple lua_States, you could only load the libraries you need, as explained
in the Lua Reference Manual, in the paragraph just above 5.1
There’s also a nice freely available chapter on optimization of Lua code in Lua Gems Book.