Page 1 of 1

lovel.filesystem.load and Lua files in working directory

Posted: Sat Jan 05, 2013 12:46 pm
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.

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

Posted: Sat Jan 05, 2013 11:26 pm
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.

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

Posted: Sat Jan 05, 2013 11:37 pm
by WheresYourUniform
Annnd nevermind. require 'sub/file' did the trick.

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

Posted: Sun Jan 06, 2013 6:08 pm
by T-Bone
The ".lua" in require is old syntax that really never made any sense.