[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Use lua_State as local variable in C function call, but not to load instructions each time
- From: Huang Lin <hlpurify@...>
- Date: Sat, 2 Jun 2007 23:23:16 +0800 (CST)
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
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?