Closed its-danny closed 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'"
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')
...
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
?
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.
Alright then, thanks.
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.