Can't make require function work [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
mitzi65
Prole
Posts: 3
Joined: Fri Jan 06, 2017 1:54 am

Can't make require function work [SOLVED]

Post 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
Error Message
Untitled.png (35.2 KiB) Viewed 5714 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?
Last edited by mitzi65 on Fri Jan 06, 2017 2:45 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Can't make require function work

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
mitzi65
Prole
Posts: 3
Joined: Fri Jan 06, 2017 1:54 am

Re: Can't make require function work

Post 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?)
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Can't make require function work

Post by zorg »

You need to do:
local sti = require "sti/sti"
since the sti lua file is in the sti folder.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Can't make require function work

Post 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

Code: Select all

local sti = require "sti.sti"
Because require takes module names, not paths, so you use dots instead of slashes.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
mitzi65
Prole
Posts: 3
Joined: Fri Jan 06, 2017 1:54 am

Re: Can't make require function work

Post by mitzi65 »

Oh, it worked! Thank you very much guys!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Can't make require function work

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Can't make require function work

Post 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
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Can't make require function work

Post 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.
When I write def I mean function.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Can't make require function work

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 220 guests