[0.17.6] require may behave unexpectedly when loading files from other mods

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
Post Reply
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

[0.17.6] require may behave unexpectedly when loading files from other mods

Post by theRustyKnife »

Say we have mod A with the files config.lua and api.lua and mod B which also contains a config.lua file. Mod A's api.lua file contains something like:

Code: Select all

local config = require 'config'
-- Some code
If mod B then does

Code: Select all

local config = require 'config'
it will get the content of mod A's config.lua, instead of it's own.

This works as it should from the perspective of require and package.loaded, but the programmer is likely to not expect this behavior, which could easily lead to some hard to find bugs.

I don't really know how this should be solved properly, but one (hopefully feasible) idea is to switch the package.loaded table depending on which mod the current file belongs to.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.17.6] require may behave unexpectedly when loading files from other mods

Post by Rseding91 »

Thanks for the report. There's no solution to this that doesn't break every mod out there.

In your own code you can solve it a few ways: change the name or better use the absolute path for the require.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.6] require may behave unexpectedly when loading files from other mods

Post by Klonan »

oof this seems nasty, especiallly as every mod out there has its own flavour of 'util'...

Post Reply

Return to “Minor issues”