Page 1 of 1

love - supporting multiple directories

Posted: Mon Oct 23, 2017 5:40 pm
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?

Re: love - supporting multiple directories

Posted: Mon Oct 23, 2017 7:31 pm
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.

Re: love - supporting multiple directories

Posted: Mon Oct 23, 2017 7:54 pm
by hlship
That's a bit of a non-sequitur.

Re: love - supporting multiple directories

Posted: Mon Oct 23, 2017 8:51 pm
by Azhukar
'arg' is a global variable containing all arguments passed to love executable, you can access it from conf.lua or anywhere else.

Re: love - supporting multiple directories

Posted: Mon Oct 23, 2017 9:21 pm
by zorg
Edited my post because wow i can't read. :monocle:

Re: love - supporting multiple directories

Posted: Mon Oct 23, 2017 10:37 pm
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.

Re: love - supporting multiple directories

Posted: Tue Oct 24, 2017 10:21 am
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.

Re: love - supporting multiple directories

Posted: Tue Oct 24, 2017 11:34 am
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)

Re: love - supporting multiple directories

Posted: Tue Oct 24, 2017 10:24 pm
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.