Protect game tables and Lua libraries during data stage

Things that we aren't going to implement
Post Reply
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Protect game tables and Lua libraries during data stage

Post by eduran »

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.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by Nexela »

Seconded! for debug at least.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by eradicator »

Thirded.
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.

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

Re: Protect game tables and Lua libraries during data stage

Post by Rseding91 »

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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by eradicator »

I welcome our new local variable overlords. :D
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.

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by eduran »

Maybe something along those lines, for data stage only?
eradicator wrote:
Wed May 08, 2019 6:14 pm
so in control everybody could still be free to shoot themselfs in the foot?)
No problem with that. But during the data stage, everyone's feet are at risk :D

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

Re: Protect game tables and Lua libraries during data stage

Post by Rseding91 »

eduran wrote:
Wed May 08, 2019 6:18 pm
Maybe something along those lines, for data stage only?
eradicator wrote:
Wed May 08, 2019 6:14 pm
so in control everybody could still be free to shoot themselfs in the foot?)
No problem with that. But during the data stage, everyone's feet are at risk :D
That doesn't protect if someone does math = nil. It only protects if someone does math.random = nil.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by eradicator »

Rseding91 wrote:
Wed May 08, 2019 8:09 pm
eduran wrote:
Wed May 08, 2019 6:18 pm
Maybe something along those lines, for data stage only?
eradicator wrote:
Wed May 08, 2019 6:14 pm
so in control everybody could still be free to shoot themselfs in the foot?)
No problem with that. But during the data stage, everyone's feet are at risk :D
That doesn't protect if someone does math = nil. It only protects if someone does math.random = nil.
Or against setmetatable(_ENV,nil) or rawset(_ENV,math,nil). :twisted:
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.

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 222
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by mrudat »

Perhaps a sanity check after a mod is run that the expected globals are still there?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by eradicator »

mrudat wrote:
Thu May 09, 2019 7:07 am
Perhaps a sanity check after a mod is run that the expected globals are still there?
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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Protect game tables and Lua libraries during data stage

Post by darkfrei »

Why we cannot just insert tables to data.raw? It looks like read-only table.

Code: Select all

data.raw = {new_type = {type = "new_type", name = "new-name"}}
Or

Code: Select all

table.insert (data.raw.inserter, {type = "inserter", name = "new-inserter"})

Post Reply

Return to “Won't implement”