[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Use lua_State as local variable in function call, but not to load instructions each time
- From: Sam Roberts <sroberts@...>
- Date: Mon, 4 Jun 2007 09:55:19 -0700
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.