whats the difference in these two statements

this works

bb = ‘someModuleFile’
package.loaded[bb] = nil

and this doesnt

package.loaded.someModuleFile = nil

and if i print out package.loaded using pairs it shows someModuleFile as a table and from what i read package.loaded is just a table

Are you sure?

I did a quick test (with the “json” module), and it looks like it’s working…

package.loaded.json = nil

removed the module.

Which module are you trying with?

thx
yes in my situation I’m sure.
I have my files in folders
in the root folder I have a folder called files and main.lua. in the folder I have more folders called images, requiresA, requiresB and a file that is required from main.lua. in this file it requires a file from requiresA. later in code a file from requiresB is loaded and it needs to run a function from requiresA which will remove the requiresA file. if I try to unload it using the second method above it doesn’t unload. if I use the first method it does.

I know this arrangement sounds a bit complicated. I’m building a module that will be used by others. and it has core files that are needed for it to work which are stored in requiresA and the user will be able to get plugin files which will add more function to or replace core functions to the module which will be stored in requiresB. if the plugin is replacing core functions I want those removed.

if I print out the package.loaded table it showed my required files as
packaged.loaded.files.requiresA.moduleFile
if I used package.loaded.files.requiresA.moduleFile = nil it wouldn’t unload but it I did
file = ‘files.requiresA.moduleFile’
package.loaded[file]=nil it would work

anyway I just thought it was odd that one way worked and the other didn’t. I would get an error saying file didn’t exist.

hope all this makes some since to you I know it sounds like I’m rambling lol

No problem. It makes perfect sense  :).

It’s a bit of an unusual setup, and it’s the extra layers of subfolders that’s causing the issue.

I simulated the setup by creating the following folder structure:

files->requireA->moda.lua

After loading the module I printed the package.loaded table and I saw that the module name for the ‘moda’ module above is defined as a string for the whole path to the module (“files.requireA.moda”), and not as individual components. That’s why your second example works.

What this means is whatever you put in the require() statement will become the module name in package.loaded regardless if it’s in multiple subfolders or not.

yes it is unusual setup but when I release the module it will make perfect since

all the user will need to do is drop a plugin in the plugin folder and my code will automatically find it and run it

require treating it as a string makes since now

Are you sure?

I did a quick test (with the “json” module), and it looks like it’s working…

package.loaded.json = nil

removed the module.

Which module are you trying with?

thx
yes in my situation I’m sure.
I have my files in folders
in the root folder I have a folder called files and main.lua. in the folder I have more folders called images, requiresA, requiresB and a file that is required from main.lua. in this file it requires a file from requiresA. later in code a file from requiresB is loaded and it needs to run a function from requiresA which will remove the requiresA file. if I try to unload it using the second method above it doesn’t unload. if I use the first method it does.

I know this arrangement sounds a bit complicated. I’m building a module that will be used by others. and it has core files that are needed for it to work which are stored in requiresA and the user will be able to get plugin files which will add more function to or replace core functions to the module which will be stored in requiresB. if the plugin is replacing core functions I want those removed.

if I print out the package.loaded table it showed my required files as
packaged.loaded.files.requiresA.moduleFile
if I used package.loaded.files.requiresA.moduleFile = nil it wouldn’t unload but it I did
file = ‘files.requiresA.moduleFile’
package.loaded[file]=nil it would work

anyway I just thought it was odd that one way worked and the other didn’t. I would get an error saying file didn’t exist.

hope all this makes some since to you I know it sounds like I’m rambling lol

No problem. It makes perfect sense  :).

It’s a bit of an unusual setup, and it’s the extra layers of subfolders that’s causing the issue.

I simulated the setup by creating the following folder structure:

files->requireA->moda.lua

After loading the module I printed the package.loaded table and I saw that the module name for the ‘moda’ module above is defined as a string for the whole path to the module (“files.requireA.moda”), and not as individual components. That’s why your second example works.

What this means is whatever you put in the require() statement will become the module name in package.loaded regardless if it’s in multiple subfolders or not.

yes it is unusual setup but when I release the module it will make perfect since

all the user will need to do is drop a plugin in the plugin folder and my code will automatically find it and run it

require treating it as a string makes since now