Cross-mod require() limitations?
Posted: Sat Nov 03, 2018 10:47 am
(This is not strictly a request. But as it is highly technical i feel it is unfit for the suggestions forum.)
So now that 0.17 is going to have the ability to require() other mods files i have thought about that a bit. And while i can see great potential for building libraries and a community of code sharing, i can also see great potential for bugs. If i write a module for my own mods without explicitly considering the possibility of another mod requiring it then, especially in the data phase, this is going to lead to serious name conflicts for global variables, which will likely break both mods involved. In the control stage every event handler would be run twice, etcpp. There's also the legal side where it might be against the license of a mod to be require()'ed by another. And i'd honestly prefer not having to rely on other mod authors to do "the right thing" to keep my own mods bug-free.
So i was wondering if anyone thought about putting some sort of limitation on that? Maybe a per module opt-in value? Or some entry in info.json? Or a new top-level file required.lua which is the only file that can be cross-required so i can precisely decide what to export and what not?
So now that 0.17 is going to have the ability to require() other mods files i have thought about that a bit. And while i can see great potential for building libraries and a community of code sharing, i can also see great potential for bugs. If i write a module for my own mods without explicitly considering the possibility of another mod requiring it then, especially in the data phase, this is going to lead to serious name conflicts for global variables, which will likely break both mods involved. In the control stage every event handler would be run twice, etcpp. There's also the legal side where it might be against the license of a mod to be require()'ed by another. And i'd honestly prefer not having to rely on other mod authors to do "the right thing" to keep my own mods bug-free.
So i was wondering if anyone thought about putting some sort of limitation on that? Maybe a per module opt-in value? Or some entry in info.json? Or a new top-level file required.lua which is the only file that can be cross-required so i can precisely decide what to export and what not?