I have a file setup like this:
main.lua (requires 'mydir.b' and then 'b')
b.lua
mydir/
b.so (LuaJIT C module)
From main, I do this:
function print_loaded()
for k, v in pairs(package.loaded) do print(k, v) end
end
print_loaded()
require 'mydir.b'
print_loaded()
-- This would now include 'mydir.b' instead of 'b':
local b = require 'b'
The outputs of the print
s show that my call to require 'mydir.b'
is setting the return value as the value of package.loaded['b']
as well as the expected package.loaded['mydir.b']
. I wanted to have package.loaded['b']
left unset so that I can later require 'b'
and not end up with the (in my opinion incorrectly) cached value from mydir.b
.
My question is: What's a good way to deal with this?
In my case, I want to be able to copy around mydir
as a subdir of any of my LuaJIT projects, and not have to worry about mydir.whatever
polluting the module namespace by destroying any later require
s of whatever
at the parent directory level.
In anticipation of people saying, "just rename your modules!" Yes. I can do that. But I'd love to know if there's a better solution that allows me to simply not have to worry about the name collisions at all.