Read-only access to files inside active mods

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Shemp
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 19, 2026 6:51 pm
Contact:

Read-only access to files inside active mods

Post by Shemp »

Sorry if this is an exhausted topic, I did try using search and I couldn't find a thread that was exactly the same.

I'm suggesting two functions for LuaHelpers, and they would probably only work in the Prototype stage:
  • file_exists: Returns true if the filepath contains a file.
  • read_file: Returns the contents of the file as a string, or nil if there is no file.
Crucially, these functions have exactly the same restrictions as require, except it works on all FileNames not just LUA files. You can't use them for files in script-output etc. require currently doesn't break determinism, so neither should these functions.

My motivation is the mod Modlist UI, which attempts to gather all loaded mods' metadata and display them in-game. Instead of asking for an expansion to the active_mods table, I thought it would be interesting if a mod could read another mod's info.json directly and parse it using helpers.json_to_table().

Possibly add list_files as well (similar to Unix ls command) to allow recursive exploration of a mod's file tree, but I can see why you wouldn't want that.
Last edited by Shemp on Fri Feb 13, 2026 3:59 pm, edited 2 times in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16584
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Read-only access to files inside mods

Post by Rseding91 »

This isn’t likely to happen since files outside of active mods are not guaranteed to exist on all players computers and as such would cause desyncs if used in multiplayer.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Shemp
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 19, 2026 6:51 pm
Contact:

Re: Read-only access to files inside mods

Post by Shemp »

Shemp wrote: Fri Feb 13, 2026 2:30 pm Crucially, these functions have exactly the same restrictions as require, except it works on all filenames not just LUA files. You can't use them for files in script-output etc. require currently doesn't break determinism, so neither should these functions.
It's only supposed to work on files inside active mods. So the argument would need to be a valid FileName.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16584
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Read-only access to files inside mods

Post by Rseding91 »

So functionally making “require” for non lua files and having it return them as a binary blob (string).
If you want to get ahold of me I'm almost always on Discord.
User avatar
Shemp
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 19, 2026 6:51 pm
Contact:

Re: Read-only access to files inside mods

Post by Shemp »

Rseding91 wrote: Fri Feb 13, 2026 3:16 pm So functionally making “require” for non lua files and having it return them as a binary blob (string).
Yes that sounds correct, but it would work on any file (including LUA files). My reasoning is, if it's safe to run require on these files, why isn't it safe to run read_file?

I don't know if there would be issues with particularly large files, you may want to include an argument for a size limit and/or a seek offset.
User avatar
Meddleman
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Mon Jun 26, 2017 7:39 pm
Contact:

Re: Read-only access to files inside active mods

Post by Meddleman »

Mod author of Modlist UI here. I can only minimally chime in, deferring to Shemp's more thorough knowledge than mine.

As they mentioned, I was originally considering making a post asking if LuaBootstrap.active_mods could expose a bit more of the currently active mod's meta data/info.json fields, such as author,title, etc.
The cherry on the cake would be dynamically displaying each active mod's thumbnail, but reading images at runtime would require file parsing, not just outputting a string, which I'm assuming is potentially unsafe.

Obviously, being much more flexible on what can be dynamically read and required at runtime would open the door for many other mods to implement their own thing, instead of just expanding on LuaBootstrap.active_mods. I can think of several combinator-modders that would enjoy string output in this manner.
Last edited by Meddleman on Fri Feb 13, 2026 7:49 pm, edited 1 time in total.
User avatar
Shemp
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 19, 2026 6:51 pm
Contact:

Re: Read-only access to files inside active mods

Post by Shemp »

Thinking more about Rseding's question (reading in binary mode vs text mode), these are the main things I'd like to use these functions for:
  • Parsing JSON data from a file, or parsing other kinds of text file (e.g. locale files)
  • Checking if a certain asset is present (an image or sound file) and conditionally declaring a prototype with this information
  • Checking if a certain LUA file exists, and conditionally calling require on it. (This would be analogous to checking LuaRemote::interfaces.)
Hopefully binary mode would enable all of these possibilities.
Post Reply

Return to “Modding interface requests”