How do i change the source directory?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How do i change the source directory?
I want all the source files to be under the /src/ folder, how would i change that?
Re: How do i change the source directory?
You can pass the root directory as an argument to the "love" command
The only issue is you'll have to put all your assets and any data local to the game in there too. If you want to have all of that separated in your project you'll have to write some script to move all code and assets together for running.
Code: Select all
> love src
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How do i change the source directory?
You don't change anything, you just put your code in the /src/ folder (except main.lua, that needs to be in the project root folder) and require your lua files with src. prepended to them.
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.
Re: How do i change the source directory?
Thank you very much guys! Passing the directory argument did it.
I don't know how I didn't think of that
I don't know how I didn't think of that
Re: How do i change the source directory?
Just for the giggles, I tried (and succeeded) to have main.lua in src/ too. But it's a dirty trick, not recommended for production; just a funny experiment.
I first added this at the top of conf.lua (which DOES need to be in the top folder):
But there's still a problem: boot.lua won't try to require main.lua if it doesn't find it in the root folder. I worked around that by creating a directory called... main.lua, in the top folder. Since "something" called main.lua exists, boot.lua is happy and proceeds to require it. Then the search path specifies to search in src/ first, and that's where the actual main.lua is, so it is run.
I first added this at the top of conf.lua (which DOES need to be in the top folder):
Code: Select all
package.path = "src/?.lua;" .. package.path
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How do i change the source directory?
This is also good for having all code files in src be required without the need to prepend src. to the filenames.pgimeno wrote: ↑Thu Mar 30, 2023 3:35 pm I first added this at the top of conf.lua (which DOES need to be in the top folder):Code: Select all
package.path = "src/?.lua;" .. package.path
...then again, you probably would want to call love.filesystem.setRequirePath instead of just directly setting package.path maybe.
This sounds like something that would need a bit of fine-tuning in the source, so that boot.lua checks whether the main.lua is actually a file (or symlink) or not... since if there is a folder called main.lua, but you didn't set up further shenanigans, then it'll probably error out currently with an unhelpful error message, no?pgimeno wrote: ↑Thu Mar 30, 2023 3:35 pm But there's still a problem: boot.lua won't try to require main.lua if it doesn't find it in the root folder. I worked around that by creating a directory called... main.lua, in the top folder. Since "something" called main.lua exists, boot.lua is happy and proceeds to require it. Then the search path specifies to search in src/ first, and that's where the actual main.lua is, so it is run.
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.
Re: How do i change the source directory?
I'm more of the opinion that adding too many checks to protect users against themselves bloats the program for use cases that are too rare to be of any significance - like having a directory called main.lua as in this hack.
That said, I'd prefer if require('main') is wrapped in a pcall rather than checking in advance if it exists, because as evidenced above, it might not error after all. It's not just that it's easier to ask for forgiveness than permission (EAFP); it actually enables a feature in this case.
That said, I'd prefer if require('main') is wrapped in a pcall rather than checking in advance if it exists, because as evidenced above, it might not error after all. It's not just that it's easier to ask for forgiveness than permission (EAFP); it actually enables a feature in this case.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests