Hey,
I'm trying to figure out how Factorio and Angels Refining uses Lua Require but outside of Factorio I can't seem to get the same behaviour.
I opened a Stackoverflow question: https://stackoverflow.com/questions/535 ... quire-path
The line is question is the first line in this file:
https://github.com/Arch666Angel/ModsCur ... ctions.lua
Which originally included here: https://github.com/Arch666Angel/ModsCur ... ta.lua#L21
I'm trying to figure out how to configure Lua in my external tool to ensure that the require in override-functions.lua uses the correct path (relative to that file). Instead it's searching for paths relative to data.lua and a bunch of other hardcoded paths I have configured.
Any help would be appreciated.
Thanks.
Help With Lua Require
Re: Help With Lua Require
Thanks Dave but I think the problem is deeper than that. Sounds like I'll need to completely override the require function and make it dynamically find files in the current directory. I haven't found a simpler solution which leads me to believe the Factorio devs must have done something similar to support this.
Is there really no documentation about what supports in the Mod lua for require?
Is there really no documentation about what supports in the Mod lua for require?
Re: Help With Lua Require
Here is what I used for my tech tree.
I run it in the factorio root directory in Lua 5.2.
I run it in the factorio root directory in Lua 5.2.
Code: Select all
package.path = package.path .. ';data/core/lualib/?.lua;data/base/?.lua'
defines = {
["difficulty_settings"] = {
["recipe_difficulty"] = {["normal"]=1},
["technology_difficulty"] = {["normal"]=1},
},
["direction"] = {
["north"] = 0,
["east"] = 2,
["south"] = 4,
["west"] = 6,
},
}
require "dataloader"
require "data.base.data"
for k, r in pairs(data.raw.recipe) do ...
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Help With Lua Require
Yeah, the require() function needs to contain the full path from mod root.
I know you can require from the core mod too, such as you used to require("util"), but I don't know how that factors into it.
I know you can require from the core mod too, such as you used to require("util"), but I don't know how that factors into it.
Re: Help With Lua Require
Thanks for code snippet Dave. And Thanks Bob
Actually if you look in Angels refining they use a relative path in prototypes/override-functions.
Anyways I found a custom require that works. I updated my StackOverflow answer if anyone is curious!
Actually if you look in Angels refining they use a relative path in prototypes/override-functions.
Anyways I found a custom require that works. I updated my StackOverflow answer if anyone is curious!