lovel.filesystem.load and Lua files in working directory

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
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

lovel.filesystem.load and Lua files in working directory

Post by Clavus »

I'm using TileD to create lua files that export tables full of level data. So a file level.lua looks like "return { verybigtable }".

Now I know you could do func = love.filesystem.load("level.lua") and then do func() to return the table. The problem is, I want to have the level lua files within the source directory, so within the .love file. How can I make LOVE reach those files? I tried love.filesystem.load("level.lua"), love.filesystem.load(love.filesystem.getWorkingDirectory().."/level.lua"), etc.

EDIT: oh it seems I can just do require("level.lua") and it'll return the table. Was overthinking the problem.
WheresYourUniform
Prole
Posts: 2
Joined: Sat Jan 05, 2013 10:54 pm

Re: lovel.filesystem.load and Lua files in working directory

Post by WheresYourUniform »

Have you (or anyone else reading this...) had any luck loading lua files from subdirectories within the love directory? I've tried doing this with something like

require '/sub/something.lua'

but it doesn't work because the project path is centered on the love executable, not the main.lua directory. I'm not sure how to adjust the project path to account for this because I haven't found an obvious way to return the main love directory (getWorkingDirectory() from love.filesystem doesn't return the right one, for some reason? Maybe because I'm using eclipse?) and I don't want to use an absolute reference.

I'm sure there's a way to do it, and it's probably obvious, I just haven't been able to figure it out.
WheresYourUniform
Prole
Posts: 2
Joined: Sat Jan 05, 2013 10:54 pm

Re: lovel.filesystem.load and Lua files in working directory

Post by WheresYourUniform »

Annnd nevermind. require 'sub/file' did the trick.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: lovel.filesystem.load and Lua files in working directory

Post by T-Bone »

The ".lua" in require is old syntax that really never made any sense.
Post Reply

Who is online

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