Problems with package.path and relative paths

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
RandyKnapp
Prole
Posts: 2
Joined: Tue Feb 21, 2012 3:35 am

Problems with package.path and relative paths

Post by RandyKnapp »

Hello lovers,

This is my first post on these very fine forums, and I'm quite excited to be using LOVE for my game programming needs!

Here is my issue: I have project arranged like this:

root
->main.lua (this require's the test module)
->lua
--->test.lua

And everything works just fine if I run my code from the root directory there. I can do it by making a .love and placing it there and double-clicking it, I can run love from the command line and give it the root directory. Those both work.

However, if I try to drag that love onto the LOVE icon on my desktop, or try to drag the root directory onto that icon, I get errors telling me that it can't find the files and checking the lua package.path and all that.

I've included the code for you nice people to look at if you're so inclined.

Please, if I've not explained myself clearly enough, or the code does not work for you, please ask and I'll try to explain better. Thanks very much for taking a look at this issue. :awesome:
Attachments
test.love
The test project reproducing this issue
(1021 Bytes) Downloaded 128 times
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Problems with package.path and relative paths

Post by tentus »

You should mention this: (you sort of do but it still took me by surprise when I looked at your source)

Code: Select all

-- These are all the places that the require function will look
package.path = "./?.lua;"..   -- Same folder
    "./lua/?.lua;"..          -- In the lua folder
    "./lua/?/?.lua;"..        -- In the lua folder, inside a directory of the same name as the module
    "./lua/util/?.lua"        -- In the lua/util folder
Wouldn't it be easier and more organized to use the path in the require, rather than having all that mess and then hope that you never call two things the same name?
Kurosuke needs beta testers
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Problems with package.path and relative paths

Post by Boolsheet »

The require loader LÖVE uses for the game source and save directory ignores package.path and rolls its own hardcoded method.
In a similar style to the patterns used in package path it can be described as "<save/game directory>/?.lua;<save/game directory>/?/init.lua".
0.7.2 also does "<save/game directory>/?" if the string passed to require ends with ".lua", but that will be dropped in 0.8.0.
Shallow indentations.
RandyKnapp
Prole
Posts: 2
Joined: Tue Feb 21, 2012 3:35 am

Re: Problems with package.path and relative paths

Post by RandyKnapp »

Thanks tentus, I guess I was assuming that LOVE used the package.path.

I'll try using the full path in the requires.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 12 guests