You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"The (require) function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module. "
That is, Lua's "require" will not re-load a module for the sake of performance.
So you're coding up Lua modules in a totally wrong way. We usually use Lua modules this way instead:
-- test.lua
module("test", package.seeall)
function a()
print("test.lua")
end
And then in your content_by_lua_file directive's lua file:
-- concat.lua
local test = require("test")
test.a()
You will see the "test.lua" output on every request as you'd expect.
Activity
agentzh commentedon Jan 24, 2011
This is more like a Lua question. To understand why this happens, see http://www.lua.org/manual/5.1/manual.html#pdf-require
To quote the key sentence:
"The (require) function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module. "
That is, Lua's "require" will not re-load a module for the sake of performance.
So you're coding up Lua modules in a totally wrong way. We usually use Lua modules this way instead:
And then in your content_by_lua_file directive's lua file:
You will see the "test.lua" output on every request as you'd expect.
luoqi commentedon Jan 24, 2011
thank you!!