hooks or something hook like

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

hooks or something hook like

eugeny gladkih-2
Hi,

the prelude - we're using Lua as a scripting language of our
embedded web-server. the problem is there are a lot of short
living and somtimes big enough scripts loading very often. that
is performance problem. we've written file cache wich holds the
source of used Lua scripts ant their compiled representation
dumped just after loading. it sounds to be good, but the most
scripts use 'require'. well, we've written 'require'
replacement. it's easy, 'cuz we dont't use 'dofile' or something
like that. so, everything seems to be going well. but... I'm
thinking about Lua 5.1 integration into our software. there is
new packaging strategy, new 'require', I guess, and maybe
something else changed, too. It's not right way to hack
everytime the standard library and VM.

the better way is having the hook which should be called from
VM/libraries when they need the file be loaded I guess. And the
coolest feature is the possibility to write that hook in Lua
itself :) does anybody agree with me?

--
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com
Reply | Threaded
Open this post in threaded view
|

Re: hooks or something hook like

Luiz Henrique de Figueiredo
> the better way is having the hook which should be called from
> VM/libraries when they need the file be loaded I guess.

If I understand you correctly, that's the idea of package.preload:
        http://www.lua.org/manual/5.1/manual.html#pdf-package.preload

--lhf
Reply | Threaded
Open this post in threaded view
|

Re: hooks or something hook like

eugeny gladkih-2
>>>>> "LHdF" == Luiz Henrique de Figueiredo <[hidden email]> writes:

 >> the better way is having the hook which should be called from
 >> VM/libraries when they need the file be loaded I guess.

 LHdF> If I understand you correctly, that's the idea of package.preload:
 LHdF> http://www.lua.org/manual/5.1/manual.html#pdf-package.preload

Not exactly, the main problem is that the Lua VM is not living
forever. it's started on demand and dies as soon as request
processed. I can create the pool of the VMs, it's not a
problem but it leads to another problem - how can I share
`package' table between all VMs? How can I share the code
compiled and being executed in one VM with another one? How can
I invalidate compiled code when disk file has been changed? How
can I throw away the expired code from the cache? I'm afraid
only by full replacement of the `require' function as it is
now. maybe I'm wrong.

--
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com
Reply | Threaded
Open this post in threaded view
|

Re: hooks or something hook like

Roberto Ierusalimschy
> I'm afraid only by full replacement of the `require' function as it is
> now.

Can't you just add a new loader to do what you want?

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: hooks or something hook like

eugeny gladkih-2
>>>>> "RI" == Roberto Ierusalimschy <[hidden email]> writes:

 >> I'm afraid only by full replacement of the `require' function as it is
 >> now.

 RI> Can't you just add a new loader to do what you want?

I'll try

--
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com