I would like to load a Lua script into my C++ program, and then invoke that script multiple times in separate threads. I'm trying to avoid loading the script in each thread (why go through that overhead).
I'm thinking something like this in the C++ program:
create lua state L
load script into L
and in n threads do:
create local lua state Si (i = 1..n, i.e., separate state per thread)
grab "compiled" script from L and invoke in the context in Si
Is there a "standard" approach to doing this? The primary goal is to avoid having each thread load the script. The script may also be executed multiple times in state Si. Note that the scripts running in separate threads are not cooperating (i.e., they know nothing about each other and we would like to keep it that way).