OT: 'best' dynamic language
manlio_perillo at libero.it
Sat Apr 26 14:46:00 MSD 2008
Igor Sysoev ha scritto:
> On Sat, Apr 26, 2008 at 11:59:38AM +0200, Manlio Perillo wrote:
>> Igor Sysoev ha scritto:
>>> The problem is that interpreter MUST TEST EVERY operation result that
>>> may fail on memory allocation. And it MUST return an error to all higher
>>> levels, closing and freeing all allocated resources on the back way.
>>> The existent interpreters either do not test result in most cases (perl),
>>> or simply exit(), or in best case they throw exception. Exceptions are easy
>>> way to program (you not need to test most operations) and cheap way to test
>>> results (for the same reason), but they may lead to socket/file
>> I understand the problem, however I think that Lua is still usable.
>> I'm reading the source code of Lua io library, and any opened file is
>> closed when reached by the gc.
>> This means that when Nginx detects an error, it can just force a full gc
>> If this still does not sounds safe, Nginx can just create a Lua state
>> (interpreter) for each request, finalizing it when the request is finalized.
>> This is both feasible and efficient (but better is one of Lua language
>> developer can confirm it).
> Can this per request interpreter run precompiled code, or will it compile
> it on its creation ?
You can precompile all the Lua code at Nginx configuration time:
The lua_load function reads and parses a Lua code chunk and return (in
the Lua stack) the compiled code (or an error code).
So, if I'm not wrong, you need to:
1) Create a Lua state at the begin of the configuration phase
2) Use this Lua state for precompiling all the Lua code in Nginx
3) Finalize this Lua State at the end of configuration phase
4) For each request create a new Lua state
5) Use this Lua state for executing the precompiled script code
6) Finalize the Lua state at the end of the request
But, again, I have never used Lua, I'm just reading the reference manual
and the source code, so better if a Lua developer can confirm this.
Regards Manlio Perillo
More information about the nginx