lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday 02 August 2005 2:26 pm, William Trenker wrote:
> What is the "proper" way to reload a module on the fly?  I am running
> Xavante and have a custom handler that uses a module.  I want to be
> able to change the module's source code and have the changes re-loaded
> automatically without stopping Xavante.

i think in your case it's easier to use loadfile() instead of require()

something like:

local lastT = 0
local lastFunc

function getScript (n)
    local attr = lfs.attributes (n)
    local t = attr.modification
    if t > lastT then
        lastFunc = loadfile (n)
        lastT = attr.modification
    end
    return lastFunc
end

then you just call getScript(), and it'll reload your module only if it has 
been modified.

-- 
Javier

Attachment: pgpEY1EQMbJ_5.pgp
Description: PGP signature