I just implemented a script-cache for MySQL Proxy and had to learn a bit more about lua internals. As a result I wrote two functions which are generic enough for general consumption:
-
luaL_loadfile_factory() -
luaL_loadstring_factory()
They also show how to write a lua_Reader for
lua_load().
The #lua channel on freenode was a
great help, as always.
LUA provide several loaders:
- luaL_loadstring
- luaL_loadbuffer
- luaL_loadfile
and you can create your own if you have to.
Now, why the need for a new loader ?
The proxy we have
- a global scope caches the scripts
- this cache reloads the scripts if they changed on disk
- each thread executes the same script
- each thread has its own …