Paths for the Require Function

Hi. Can anyone tell me how to require a module that is located within a parent folder of the calling lua file?

I can use the dot notation to dig down into the folder navigation. ParentFolder.SubFolder.File but i’ve no idea how to reference it back up.

Main Folder


module_needed.lua

    Sub Folder

    --------------------------

    calling_file.lua

For images, I would use …/ but this doesn’t work for requiring modules.

local module = require("???")

If you want to access that lua file just use
local myModule = require(“module_needed”)

You don’t need to use “…” just use the folder path.

Also, you cannot and should not try to access any files above root (folder where main.lua is).

So,  if are trying to accesses images from main.lua (as shown hierarchically below) that is very wrong and will not build.

/parent | | /images/\*.png | | /project/    |    / main.lua

If, on the other hand, you have this situation:

/project/ | main.lua | | scripts/ | scriptA.lua | | moreScripts/ | | scriptB.lua

scriptB.lua would require scriptA.lua as follows:

require "scripts.scriptA"

Beware
In the above scenario, A can require B -OR- B can require A, but they can’t both require eachother at the file level or you’ll get an error.  There are ways to handle this, but that is advanced and a bit specific to explain here.

If you want to access that lua file just use
local myModule = require(“module_needed”)

You don’t need to use “…” just use the folder path.

Also, you cannot and should not try to access any files above root (folder where main.lua is).

So,  if are trying to accesses images from main.lua (as shown hierarchically below) that is very wrong and will not build.

/parent | | /images/\*.png | | /project/    |    / main.lua

If, on the other hand, you have this situation:

/project/ | main.lua | | scripts/ | scriptA.lua | | moreScripts/ | | scriptB.lua

scriptB.lua would require scriptA.lua as follows:

require "scripts.scriptA"

Beware
In the above scenario, A can require B -OR- B can require A, but they can’t both require eachother at the file level or you’ll get an error.  There are ways to handle this, but that is advanced and a bit specific to explain here.