Protect game tables and Lua libraries during data stage
Protect game tables and Lua libraries during data stage
Not really an interface request, but I did not know where else to put it.
Would it be possible to prevent mods from overriding built-in game tables and Lua libraries during the data stage? If one mod does something stupid like "math = 0", all following mods are in trouble. Ideally the responsible mod should throw an error, not the mod trying to access "math". You can even do stuff like settings = 0 or data = 0.
I know it will result in an error either way, but it would be nice if reports like this were directed towards whoever overrode debug, instead of my mod.
Would it be possible to prevent mods from overriding built-in game tables and Lua libraries during the data stage? If one mod does something stupid like "math = 0", all following mods are in trouble. Ideally the responsible mod should throw an error, not the mod trying to access "math". You can even do stuff like settings = 0 or data = 0.
I know it will result in an error either way, but it would be nice if reports like this were directed towards whoever overrode debug, instead of my mod.
Re: Protect game tables and Lua libraries during data stage
Seconded! for debug at least.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Protect game tables and Lua libraries during data stage
Thirded.
And for table/string at least, so ppl don't inject their own shitty code.
And for table/string at least, so ppl don't inject their own shitty code.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Protect game tables and Lua libraries during data stage
I'm not against the idea but Lua includes no such "protection" system so I would have to add it and then it's going to incur a performance overhead for every single global assignment for the rest of time.
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Protect game tables and Lua libraries during data stage
I welcome our new local variable overlords.
Would it make *reading* globals slower too?
(And just for the record, the protection is only needed for settings/data stage, so in control everybody could still be free to shoot themselfs in the foot?)
Would it make *reading* globals slower too?
(And just for the record, the protection is only needed for settings/data stage, so in control everybody could still be free to shoot themselfs in the foot?)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Protect game tables and Lua libraries during data stage
Maybe something along those lines, for data stage only?
No problem with that. But during the data stage, everyone's feet are at riskeradicator wrote: ↑Wed May 08, 2019 6:14 pm so in control everybody could still be free to shoot themselfs in the foot?)
Re: Protect game tables and Lua libraries during data stage
That doesn't protect if someone does math = nil. It only protects if someone does math.random = nil.eduran wrote: ↑Wed May 08, 2019 6:18 pm Maybe something along those lines, for data stage only?
No problem with that. But during the data stage, everyone's feet are at riskeradicator wrote: ↑Wed May 08, 2019 6:14 pm so in control everybody could still be free to shoot themselfs in the foot?)
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Protect game tables and Lua libraries during data stage
Or against setmetatable(_ENV,nil) or rawset(_ENV,math,nil). :twisted:Rseding91 wrote: ↑Wed May 08, 2019 8:09 pmThat doesn't protect if someone does math = nil. It only protects if someone does math.random = nil.eduran wrote: ↑Wed May 08, 2019 6:18 pm Maybe something along those lines, for data stage only?
No problem with that. But during the data stage, everyone's feet are at risk :Deradicator wrote: ↑Wed May 08, 2019 6:14 pm so in control everybody could still be free to shoot themselfs in the foot?)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Protect game tables and Lua libraries during data stage
Perhaps a sanity check after a mod is run that the expected globals are still there?
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Protect game tables and Lua libraries during data stage
I like that vector. No need to do expensive checks. Just reset all global libraries to default after each mod. That way they can still shoot their own feet, but won't affect anyone elses.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Protect game tables and Lua libraries during data stage
Why we cannot just insert tables to data.raw? It looks like read-only table.
Or
Code: Select all
data.raw = {new_type = {type = "new_type", name = "new-name"}}
Code: Select all
table.insert (data.raw.inserter, {type = "inserter", name = "new-inserter"})