[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: precompiling
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 15 May 2000 21:09:25 -0300 (EST)
>Is there any way to access the precompiler from within lua?
Lua always precompiles chunks before running them.
>I want to have my lua code precompile files before executing dofile()
>so the next time the script is run it will run the precompiled version
>if this source file hasn't changed.
The easiest solution for this is to define a function around the whole chunk
and return it. Something like
return function ()
... (chunk code)
end
Then do
if CACHE[name]==nil or file "name" has changed then
CACHE[name]=dofile(name)
end
CACHE[name]()
Of course, you could redefined "dofile" to do this, using %dofile to get the
original "dofile". You can also hide CACHE as an upvalue to the new "dofile".
--lhf