Help With Lua Require

Place to get help with not working mods / modding interface.
Post Reply
salbris
Inserter
Inserter
Posts: 43
Joined: Sun May 24, 2015 4:50 am
Contact:

Help With Lua Require

Post by salbris »

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.


salbris
Inserter
Inserter
Posts: 43
Joined: Sun May 24, 2015 4:50 am
Contact:

Re: Help With Lua Require

Post by salbris »

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?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help With Lua Require

Post by DaveMcW »

Here is what I used for my tech tree.

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

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Help With Lua Require

Post by bobingabout »

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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

salbris
Inserter
Inserter
Posts: 43
Joined: Sun May 24, 2015 4:50 am
Contact:

Re: Help With Lua Require

Post by salbris »

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!

Post Reply

Return to “Modding help”