lua-users home
lua-l archive

Xavante / Compat-5.1: reloading a module?

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


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've been doing this:
--- myXavanteHandler.lua ---
module("myXavanteHandler")
local function myHandler(req, res, param)
 package.loaded.myModule = nil
 require"myModule"
 res.content = myModule.html(req.built_url)
 return res
end
function makeHandler (params)
 return function (req, res)
 return myHandler(req, res, params[1])
 end
end
--- end code ---
--- myModule.lua ---
module("myModule")
function html(txt)
 return "txt = "..txt.."<br />"
end
--- end code ---
The net effect is that when I change the code in myModule.lua, it will
be reloaded the next time the handler is called.
But is setting package.loaded.x to nil the design-intended way to
trigger a reload? Will this cause problems with package.preload?
Thanks,
Bill

AltStyle によって変換されたページ (->オリジナル) /