lua-users home
lua-l archive

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



You can of course use precompiled scripts, but even then setting up the Lua state will take some time & code.

An approach I've used in Lua Lanes is to have forever-looping server threads, who exchange data over receive/send connection with others. In fact, Lanes has grown now to a fairly OS-kernel-like set of features (threads ~ processes), which indeed is a part of my vision of a "virtual" operating system.

But maybe my "answer" is more than you were asking. What you'd want (imho) is ability to 'clone' the template lua_State after loading 'test.lua', and then be able to close those clones after usage. Maybe you can twist 'lua_newthread()' to do this?

Good luck. :)
-asko


Huang Lin kirjoitti 2.6.2007 kello 18:23:

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