Subdirectories in .love Files

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.
Rusky
Prole
Posts: 8
Joined: Wed May 05, 2010 1:49 pm
Location: Airship Abubalay
Contact:

Subdirectories in .love Files

Post by Rusky »

My game is big enough that I started organizing it into subdirectories. It works just fine in a directory, but once I zip it into a .love file "require("subdir/something")" stops working. It looks like the LOVE filesystem can't deal with directories- the last line of the error is "no file "subdir/something.lua" in LOVE game directories." Any suggestions?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Subdirectories in .love Files

Post by kikito »

I'm pretty experienced putting things in subdirectories. If you upload a sample .love file somewhere I can give it a look.

As a blind guess, make sure that you are using the same uppercase-lowercase combinations on your repositories and files.

For windows, a file called Main.LUA is the same as a file called main.lua. For the zip control, it isn't.
When I write def I mean function.
Rusky
Prole
Posts: 8
Joined: Wed May 05, 2010 1:49 pm
Location: Airship Abubalay
Contact:

Re: Subdirectories in .love Files

Post by Rusky »

I checked the case already; here's the .love file:
distoban.love
(384.7 KiB) Downloaded 248 times
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Subdirectories in .love Files

Post by Jasoco »

I get the same problem. If I unzip your uploaded version and run it as a package (i.e. as a folder with files) it runs fine. But when I rezip the files the way they would be for a finalized project, it gives the error again with a bunch of error jibberish...

Code: Select all

boot	[string "world.lua"]:1: module 'world/sky' not found:
	no field package.preload['world/sky']
	no file './world/sky.lua'
	no file '/usr/local/share/lua/5.1/world/sky.lua'
	no file '/usr/local/share/lua/5.1/world/sky/init.lua'
	no file '/usr/local/lib/lua/5.1/world/sky.lua'
	no file '/usr/local/lib/lua/5.1/world/sky/init.lua'
	no file './world/sky.so'
	no file '/usr/local/lib/lua/5.1/world/sky.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file "world/sky.lua" in LOVE game directories.
	stack traceback:
	[string "boot.lua"]:833: in function 'error_printer'
	[string "boot.lua"]:768: in function <[string "boot.lua"]:766>
	[C]: in function 'require'
	[string "world.lua"]:1: in main chunk
	[C]: in function 'require'
	[string "main.lua"]:1: in main chunk
	[C]: in function 'require'
	[string "boot.lua"]:282: in function <[string "boot.lua"]:215>
	[C]: in function 'xpcall'
	[string "boot.lua"]:838: in main chunk
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Subdirectories in .love Files

Post by Robin »

The problem is here:

Code: Select all

import "folder/module"
Zooming in:
/
It works if you use "folder.module", since Lua uses a dot to refer to subdirectories when requiring.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Subdirectories in .love Files

Post by kikito »

I respectfully disagree with our leader Robin.

I think the problem is that you have a folder called 'world' and also a file called 'world.lua'.

LÖVE doesn't seem to like that very much.

I tried renaming world.lua to World.lua, modified the require on main.lua and the generated .love worked. A slightly better suggestion: move it inside world/world.lua (and maybe move all those 'requires' to a specific file, i.e. world/init.lua).

By the way, your game rocks! It reminds me of my pew-pew-boom game, but better looking. Nice!
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Subdirectories in .love Files

Post by Robin »

kikito wrote:I respectfully disagree with our leader Robin.
Damn, I thought it worked, but I tested it more thoroughly and it seems you are right. :death:

And I am not your leader.
Help us help you: attach a .love.
Rusky
Prole
Posts: 8
Joined: Wed May 05, 2010 1:49 pm
Location: Airship Abubalay
Contact:

Re: Subdirectories in .love Files

Post by Rusky »

Thanks for the help, everyone.

Switched to dots for aesthetic purposes, but that wasn't the problem. In main.lua, require("world.init") works (although it would be nice if require("world") checked for "world.init" by default like Lua; should I submit that as a feature request?). However, world/init.lua errors when I require("world.sky") but works with require("world/sky"), which is even weirder because all the other requires work with dots.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Subdirectories in .love Files

Post by kikito »

I experienced some weirdness on that regard.

In PÄSSION, I allways use the following:
  • Relative paths don't seem to work. If you are inside foo/bar.lua and you want to require foo/baz.lua, you have to write foo/ again.
  • I allways use / instead of . , just because empirically it gave me less trouble (the dot got confused when parsing zipped files in some occasions, while the slash didn't)
  • I very often include the .lua file extension at the end
Here's my passion/init.lua file as a reference. The paths would look nicer without the file extensions and so many slashes, but it was just the only way I could make the thing work.

Robin:
Napoleon Bonaparte wrote:A leader is a dealer in hope
When I write def I mean function.
Rusky
Prole
Posts: 8
Joined: Wed May 05, 2010 1:49 pm
Location: Airship Abubalay
Contact:

Re: Subdirectories in .love Files

Post by Rusky »

Yeah, I'll go with slashes for now. I'm posting a bug report.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests