Kadoba / Advanced-Tiled-Loader

Imports Tiled maps into Lua for the LÖVE game engine. (NO LONGER IN DEVELOPMENT)
183 stars 30 forks source link

Allow me to stick the library folder wherever I want #4

Closed its-danny closed 12 years ago

its-danny commented 12 years ago

Right now, it seems if I don't put the folder in the root directory, init.lua won't load any of the required files (which also load files). I'm new to Lua, and have been looking for a way to avoid this, but haven't found anything yet.

Correct me if I'm wrong or I'm just doing something wrong on my end.

its-danny commented 12 years ago

Also, I've tried setting TILED_LOADER_PATH = 'vender/AdvTiledLoader/' in main.lua but still get an error saying "no file './vender/AdvTiledLoader/Map.lua'"

floriancargoet commented 12 years ago

That's because Lua doesn't have the right pattern in its package.path variable.

You can fix that with something like :

package.path =
    './lib/?.lua;'..
    './lib/?/?.lua;'..
    './lib/?/init.lua;'..
    package.path

This would give you access to any Lua file in the lib/ folder or in a subdir with the same name or to an init.lua file.

I have Advanced-Tiled-Loader as a git submodule in my lib directory and I load it that way:

-- Tell Lua where are the modules
package.path =
        './lib/?.lua;'..
        './lib/?/?.lua;'..
        './lib/?/init.lua;'..
        package.path

-- ATL needs to know where it is
TILED_LOADER_PATH = 'lib/ATL/AdvTiledLoader/'

-- requires
local ATL = require('ATL/AdvTiledLoader')
...
its-danny commented 12 years ago

That works, awesome. Sorry about the incorrect issue, then.

I do have one question, though, which I guess is more of a Lua question. Why is it not possible for AdvTileLoader to load it's files relative to itself, without the need of changing package.path and setting TILED_LOADER_PATH?

floriancargoet commented 12 years ago

As far as I know, require() is not relative. When you require("something"), Lua substitutes "something" to the question marks in package.path and try to find a matching file. See http://www.lua.org/manual/5.1/manual.html#pdf-require for more information.

its-danny commented 12 years ago

Alright then, thanks.