Load data folder with lua outside of Factorio

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
Mat5i6
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Dec 25, 2014 4:39 pm
Contact:

Load data folder with lua outside of Factorio

Post by Mat5i6 »

Hi! As the title says, my goal is to load (require and execute) all Factorio packages inside data folder as Factorio would.

The main problem which troubles me is how the Factorio is able to manage all the require() calls from within the package. I've read the lua documentation about the require function probably 6 times already and besides the fact that it's an absolute mess I do believe that the Factorio devs had either modified and compiled their own version of lua to suit their needs or modified the require function or used something within the lua to make it work. And that's what I want to ask here. If there is someone with an insight of how this was achieved and how I could replicate it, it would really helped me.


Thanks in advance,
Mat5i6.
Last edited by Mat5i6 on Sun Nov 29, 2020 1:52 pm, edited 2 times in total.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Scan data folder with plain lua

Post by Deadlock989 »

Mat5i6 wrote:
Sun Nov 29, 2020 11:10 am
I do believe that the Factorio devs had either modified and compiled their own version of lua to suit their needs or modified the require function or used something within the lua to make it work. And that's what I want to ask here. If there is someone with an insight of how this was achieved it would really helped me.
https://lua-api.factorio.com/latest/Libraries.html

Otherwise I understand nothing from your explanation or your code example and have no idea what you are trying to achieve. It's an "absolute mess" as you put it.
Image

User avatar
Mat5i6
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Dec 25, 2014 4:39 pm
Contact:

Re: Scan data folder with plain lua

Post by Mat5i6 »

Thank you for the quick response and the link. Sorry if I wrote somewhat confusingly, since I didn't even know what I'm looking for. I've cleaned up my question so I hope now it will be more clear.

The reason why I'm asking here is that, I would like to load all the packages as Factorio would but without Factorio so I can use it later on in javascript. As such I figured that I would define my own data:extend which would store the prototypes just like data.raw does, required all the packages (order by dependency wise), converted the stored prototypes to JSON and then just returned to my JS code.

Eventually I would like to create a simple modding tool which should first collect all prototypes from dependencies and then use them in auto-complete fields, dropdowns, etc... but that's a long road ahead. Thus firstly I need to find a way to collect those prototypes but that proves to be more complicated than I thought.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Scan data folder with plain lua

Post by Deadlock989 »

Data prototypes and the files that make them are not really "packages" in the sense that I think you might mean. Prototypes are constructed in a variety of ways in Factorio base mod code. Some are just simple data:extend calls that take the whole hand-written prototype as a single hardcoded table. Others pull in re-used property values returned from functions in other required files. Yet others are generated more procedurally. All of them are just dumped into the big data.raw table in the end.

If I were attempting what you were attempting I would not be trying to override anything but be looking instead at writing a simple Factorio mod which dumps the specific prototype info I need from the prototypes (i.e. after the base mod has finished constructing them) to the log (in JSON or whatever format) and then write some other external scripts to take it from there, but there are lots of ways of approaching it. As far as I know vanilla does all of its own prototype building in the data stage with the single exception of barrelling items and recipes which are created in data-updates, so if you do your dump in data-updates.lua or data-final-fixes.lua you would catch everything the base Factorio mod creates.
Image

User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 768
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Load data folder with lua outside of Factorio

Post by ickputzdirwech »

If I understand correctly what you are talking about have a look at the following mods. Otherwise ignore me ;)

https://mods.factorio.com/mod/DataRawSerpent

viewtopic.php?f=135&t=45107
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write

User avatar
Mat5i6
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Dec 25, 2014 4:39 pm
Contact:

Re: Scan data folder with plain lua

Post by Mat5i6 »

Deadlock989 wrote:
Sun Nov 29, 2020 1:54 pm
Data prototypes and the files that make them are not really "packages" in the sense that I think you might mean. Prototypes are constructed in a variety of ways in Factorio base mod code. Some are just simple data:extend calls that take the whole hand-written prototype as a single hardcoded table. Others pull in re-used property values returned from functions in other required files. Yet others are generated more procedurally. All of them are just dumped into the big data.raw table in the end.

If I were attempting what you were attempting I would not be trying to override anything but be looking instead at writing a simple Factorio mod which dumps the specific prototype info I need from the prototypes (i.e. after the base mod has finished constructing them) to the log (in JSON or whatever format) and then write some other external scripts to take it from there, but there are lots of ways of approaching it. As far as I know vanilla does all of its own prototype building in the data stage with the single exception of barrelling items and recipes which are created in data-updates, so if you do your dump in data-updates.lua or data-final-fixes.lua you would catch everything the base Factorio mod creates.
Yeah, I probably do get where this comes from. There is no point in reinventing the wheel... I wanted to try it this way to avoid the extra hassle with placing some mod into the game, then running the game and eventually process the result once the game is loaded. When as you said, everything is placed into the big data.raw table in the end. I would just have to simulate the proper order of things but that is probably more pain than gain. Once again thank you for your help.

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Load data folder with lua outside of Factorio

Post by Bilka »

If you don't want to use a Factorio mod, I'd recommend you to use existing Factorio data dumping/interaction tools instead of reinventing the wheel. If those tools aren't to your liking, you can at least use them for guidance on how things work.

These are the (non Factorio mod) tools that I could quickly find in my bookmarks. Unsorted; documentation and feature sets vary: Some discussion of some of these tools can be found here: viewtopic.php?p=495794#p495794 and in the Github issue linked there.

Disclaimer: I have not used most of these tools. This is just a list of existing tools that I am aware of, not a recommendation for any specific tool.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding discussion”