Page 1 of 2
Can't make require function work [SOLVED]
Posted: Fri Jan 06, 2017 2:48 am
by mitzi65
Hey people, I was trying to follow the tutorial about Simple Tiled Implementation in Lua Space and I got some errors regarding the require function.
The error message is the following:
- Error Message
- Untitled.png (35.2 KiB) Viewed 6220 times
And the only code I have wrote about it until now is that:
Code: Select all
local sti = require "sti"
function love.load()
mapa = sti(teste.lua)
end
function love.update(dt)
mapa:update(dt)
end
function love.draw()
mapa:draw()
end
Does anybody know what is happening here?
Re: Can't make require function work
Posted: Fri Jan 06, 2017 4:04 am
by zorg
Hi and welcome!
Did you download STI and put it into your project folder? It's not something that comes with löve itself.
Re: Can't make require function work
Posted: Fri Jan 06, 2017 1:17 pm
by mitzi65
Thanks for the welcome!
Yep,I did. The STI folder is on the same folder as main.lua. I noticed something weird about my problem too, the require function is not working when I am using it without Löve too (just as pure lua code). Could therebr a problem with my environment variables since I am using a chromebook with linux (using crouton for chroot)? (Maybe this problem should be made in a lua forum instead of a Löve one?)
Re: Can't make require function work
Posted: Fri Jan 06, 2017 2:24 pm
by zorg
You need to do:
local sti = require "sti/sti"
since the sti lua file is in the sti folder.
Re: Can't make require function work
Posted: Fri Jan 06, 2017 2:33 pm
by Nixola
zorg wrote:You need to do:
local sti = require "sti/sti"
since the sti lua file is in the sti folder.
But that should be
Because require takes module names, not paths, so you use dots instead of slashes.
Re: Can't make require function work
Posted: Fri Jan 06, 2017 2:44 pm
by mitzi65
Oh, it worked! Thank you very much guys!
Re: Can't make require function work
Posted: Fri Jan 06, 2017 3:30 pm
by raidho36
zorg wrote:
since the sti lua file is in the sti folder.
But why? You can have an "init.lua" file in your module folder and calling "require ( modulefolder )" will call this file.
Re: Can't make require function work
Posted: Fri Jan 06, 2017 3:52 pm
by zorg
raidho36 wrote:zorg wrote:
since the sti lua file is in the sti folder.
But why? You can have an "init.lua" file in your module folder and calling "require ( modulefolder )" will call this file.
don't ask me :V
Re: Can't make require function work
Posted: Fri Jan 06, 2017 4:54 pm
by kikito
raidho36 wrote:
But why? You can have an "init.lua" file in your module folder and calling "require ( modulefolder )" will call this file.
That's Lua's fault. The implementation of `init.lua` isn't complete. It works when the library is in certain places (like when installed by LuaRocks)
but not when you are trying to use a local package. This happens consistenly in Lua 5.1, 5.2, 5.3 and LuaJIT, so I don't know whether I am getting crazy or there is some reason I don't understand.
Re: Can't make require function work
Posted: Fri Jan 06, 2017 5:47 pm
by airstruck
kikito wrote:raidho36 wrote:
But why? You can have an "init.lua" file in your module folder and calling "require ( modulefolder )" will call this file.
That's Lua's fault. The implementation of `init.lua` isn't complete. It works when the library is in certain places (like when installed by LuaRocks)
but not when you are trying to use a local package. This happens consistenly in Lua 5.1, 5.2, 5.3 and LuaJIT, so I don't know whether I am getting crazy or there is some reason I don't understand.
Are you running Debian? I had the impression this was something weird the Debian package maintainers did, and it didn't affect other platforms. I'm not sure it's Lua's fault; as far as I know they don't make any recommendation for what exactly should go in package.path (from LUA_PATH or luaconf.h), so it's just up to package maintainers to do something sensible.
It's weird that it happens in Love, though, because Love only uses the built-in loader (and package.path) as a fallback for its own loaders, which I thought fully supported the init.lua thing.