lua-users home
lua-l archive

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


> The user code for the script is wrapped in a template "function 
> <scriptName>(Param) <user code> end".

There is no need for that because a script is already a (vararg) function.
Unless you want to pass it named arguments.

> 1) Is it worth to pre-allocate a lua_State pool instead of creating it 
> every time ?

You gain a little time by avoiding to reload all libraries each time
but you'll probably have to worry about the user script leaving garbage
behind or changing or deleting library functions. So I'd say create a
new Lua state every time unless that proves to be too time consuming.

> 2) If so, in between executions is it enough to clean it using 
> settop(L,0) and
>    replacing its _ENV for a empty table ?

There's the registry to worry about too. But note that by replacing the
global table by a new empty table you lose the previously loaded libraries.
 
> 3) Instead of wrapping <user code> in the template function, could I 
> just push it
>    as a Lua chunk and pcall()-it ?

Yes, unless you need named arguments.