lua-users home
lua-l archive

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


Hi there,
 
I use lua in this way in my C program.
 
int getPrompt (char* output)
{
        lua_State *L = lua_open();  /* create state */

        if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0))
        {

        }
        /// other lua logic to get output
        lua_close(L);
}
By using a local lua_State, the C program can begin the LUA logic from a fresh environment. This is also helpful when the C function, getPrompt, was run in multithread environment that doesn't require LUA related data to be shared/exchanged between threads.
 
But it is expensive to load the LUA instructions each time when I just want a local and fresh LUA runtime environment.
 
Is it possible to load/compile the LUA scripts once, put the result in the memory, and let the local lua_State(an independent lua universes) use it?
 
Thanks,
Huang Lin