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.
lovel.filesystem.load and Lua files in working directory
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Sat Jan 05, 2013 10:54 pm
Re: lovel.filesystem.load and Lua files in working directory
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.
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.
-
- Prole
- Posts: 2
- Joined: Sat Jan 05, 2013 10:54 pm
Re: lovel.filesystem.load and Lua files in working directory
Annnd nevermind. require 'sub/file' did the trick.
Re: lovel.filesystem.load and Lua files in working directory
The ".lua" in require is old syntax that really never made any sense.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests