love - supporting multiple directories

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

love - supporting multiple directories

Post by hlship »

I'm just getting started with Love2D, but I see the need for the love command to accept multiple directories, rather than just a single one.

I'd like to see these directories as a prioritized search order.

Why?

First: in local development, I may want to add some libraries to the mix that I don't want in my released game, such as cupid.
So I could put cupid and a for-development version of conf.lua in a dev directory, and everything else in a src directory, then invoke as "love dev src" to run my game; I actually have a tiny Makefile for running things.

Second: I'm also starting to experiment with using MoonScript. Here, I might want to have .moon files in my src folder compiled to an out folder, and I'll want that out folder visible when loading libraries.

Thoughts?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love - supporting multiple directories

Post by zorg »

Yes. Use Git. That provides versioning.

Edit: Wow did i misread what you wanted; okay, so:

As Azhukar said, the arg table does contain all the parameters you pass in to löve from the commandline, there's technically no difference between the first parameter used to locate the folder where your main.lua resides and the rest of the params one would supply.

That solves the uncertainty about the cmdline params, now for the folder thing:
Löve doesn't allow neither write nor read access to folders outside the project's root directory (where your main.lua is), and the save folder you set, by default.
That said, you can do a few things:
1. You can get read access to other places if you drop a folder into your project, which will invoke the directorydropped callback.
2. You can use the basic lua io insetad of löve's filesystem (which is a wrapper over PhysFS with a few things not exposed)

Now, if you're not against monkeypatching a few things, you could use LuaJIT's FFI to actually allow love.filesystem read access to other places, like ones you pass through the commandline for example; you could also set the write directory to those as well, but PhsyFS has a 1-simultaneous-write-directory limit, so you can only ever have one assigned, and files opened in them, which kinda sucks.

There are also some people intimidated by the fact that OS makers tend to not allow access to specific folders since they may think the users to be idiotic scrubs (and they're sadly not wrong, in a sense) so people are usually discouraged from doing "crazy" stuff like takeown-ing all folders in windows, for example, to grant rwx (all) rights to themselves on windows.

That said, here's a gist that allows you to set the write folder to either the source directory or the save directory; if you want, you can expand on this to fit your needs: https://gist.github.com/zorggn/1c5298c5a10cf20152f4

Though if you want to forego all this, you can also just check with flags if 'dev' and such are in the commandline, and if your folder hierarchy is good enough, like:

Code: Select all

(root)
|-src
| |-stuff...
|
|-dev
| |-stuff...
|
|-main.lua
|-conf.lua
then you can access the files in there, maybe require(dev.init) and have an init.lua in the dev folder that initializes cupid and stuff.
Last edited by zorg on Mon Oct 23, 2017 9:26 pm, edited 3 times in total.
Me and my stuff :3True 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.
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

Re: love - supporting multiple directories

Post by hlship »

That's a bit of a non-sequitur.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: love - supporting multiple directories

Post by Azhukar »

'arg' is a global variable containing all arguments passed to love executable, you can access it from conf.lua or anywhere else.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love - supporting multiple directories

Post by zorg »

Edited my post because wow i can't read. :monocle:
Me and my stuff :3True 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.
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

Re: love - supporting multiple directories

Post by hlship »

Thanks for the feedback. I guess I wasn't being very clear that I was looking for a discussion to enhance Love to support my desired feature, rather than looking for a way to create a workaround with the current version of Love.

Essentially, and I have no idea how difficult this is, I want two (or more!) root directories.

I do think an at least temporary approach is to move my packages "down" one level, but I suspect that will be both incomplete (for the development lifecycle I'm seeking) and inelegant.
User avatar
deströyer
Prole
Posts: 32
Joined: Thu Jun 27, 2013 7:59 pm
Contact:

Re: love - supporting multiple directories

Post by deströyer »

You can specify multiple 'read files from this location'-paths by extending the package.path string with more read-locations. So if I wanted to add a path which contains a bunch of shared libraries I've written for string parsing and math, I could do something like:

Code: Select all

package.path = package.path .. "/Users/myUserName/DropBox/Projects/Programs/Shared/?.lua;"
Not completely sure how you want this to work and if this will help, though! Worth noting that package.path is a Lua feature, not a love2d feature.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love - supporting multiple directories

Post by zorg »

What would make "moving down your packages one directory level" incomplete and/or inelegant?

Also, technically, löve already has two "root" directories by default, as i said before; both the source base directory (where your main.lua is) and the save directory map to the root of the filesystem's hierarchy, so that one virtual root is actually two real directories. (there is a function to differentiate between where files/folders are in terms of the real filesystem, though)
Me and my stuff :3True 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.
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

Re: love - supporting multiple directories

Post by hlship »

I'm now thinking about a Makefile that copies a main src directory (containing Lua code and assets) to an out directory, and also compiles moon files to the same out directory, then runs Love against the out directory.
Post Reply

Who is online

Users browsing this forum: No registered users and 230 guests