How to access modules up a directory [PLEASE HELP!]
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
How to access modules up a directory [PLEASE HELP!]
I have been trying to look this up, but there is no tutorial other than LOVES Wiki. In the wiki, it stated that I can change the "require()" function's directory by using "love.filesystem.setRequiredPath(path)". I have no idea what the default value means. Here it is for reference. "?.lua;?/init.lua."
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to access modules up a directory [PLEASE HELP!]
you can use the ... vararg in the main body of a file you're requiring to get a path you can manipulate, and use that to go up a directory... IF it's not already the one where
- your main.lua is, or
- it is the root of your save folder
You don't need to mess with setRequirePath.
- your main.lua is, or
- it is the root of your save folder
You don't need to mess with setRequirePath.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
Re: How to access modules up a directory [PLEASE HELP!]
What do you mean by “vararg”. The closest thing I can think of is “Variable Arguments”. I need a cement ration please.
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
Re: How to access modules up a directory [PLEASE HELP!]
Srry, lol. I need a demonstration
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to access modules up a directory [PLEASE HELP!]
was gonna ask what you meant by that, but thanks for the clarification
Yes, i do mean the variable argument that lua has, the ellipse (...)
Here's an example:
After you have that path, some string manipulation to cut off the end to some extent is needed; in some libraries it is done that way, i just can't remember the exact solution to that; at that point, you can have just the directory of the required file, and from that, you can have the directory above it... but only if it wasn't already on the same level as main.lua since you can't go above that.
Yes, i do mean the variable argument that lua has, the ellipse (...)
Here's an example:
Code: Select all
-- bar/foo.lua
local path = ... -- this is in the file scope, and when requiring this file, it'll contain the require path it was found through
print(path)
-- main.lua
local meh = require "bar.foo"
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
Re: How to access modules up a directory [PLEASE HELP!]
I am pretty confused. I am pretty new to lua and love2d. Here is my situation. I have "state.lua" control my gamestates. One of those is the menu. In the menu script, I have to access a library for the menu gui. Here is a picture of my file structure. I want a kind of a tutorial. I just don't understand why some things are the way they are. Maybe show it in action.
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
Re: How to access modules up a directory [PLEASE HELP!]
I need help understanding it
Re: How to access modules up a directory [PLEASE HELP!]
Is there a reason you don't want to use full paths, i.e. require("data.scripts.lib.gui.button")?
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
-
- Prole
- Posts: 11
- Joined: Thu May 27, 2021 4:19 pm
Re: How to access modules up a directory [PLEASE HELP!]
Oh, I didn't realize that was an option. Thanks, I got it from here.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to access modules up a directory [PLEASE HELP!]
I did go on the assumption that you wanted to access a directory that was "above" where your main.lua was; since it's not, paths starting from that folder will work, as said by Refreezed.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: No registered users and 2 guests