lua-users home
lua-l archive

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


On Sun, Jun 03, 2007 at 10:52:23AM +0800, Huang Lin wrote:
>   [BLH] I tried to use precompiled scripts, it reduces about 80-90%
>   CPU usage in LUA logic processing. I am even thinking about to mmap
>   the precompiled scripts to memory, so that the program doesn't use
>   fopen/fread to read the instructions from the precompiled scripts.

This is easy to do, look at lua_load(), define a reader that returns
the data from the mmapped area.

>   [BLH] Yes this is what I want,  to get a clean copy of template
>   lua_State when C program begin the LUA function call.  I will try
>   'lua_newthread. I am not sure if the lua_State generated by
>   lua_newthread will share some sort of pointer with the template
>   lua_State, or other lua_State in different threads. If it is the
>   case one mess up in a LUA function call may affect others.

You can "sandbox" a script, so that it doesn't have (much) shared state.
Check the list archives, it comes up periodically. The impression I have
is its not so hard if you want to prevent scripts accidentally effecting
each other, it gets harder if you assume the script writer is malicious.

And yes, lua_newthread() creates a coroutine that initially shares
global env with the template state, but can be adjusted.

Sam