Can I require "package.file" instead of "package/file.lua"?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
willurd
Citizen
Posts: 76
Joined: Thu Mar 04, 2010 1:04 am
Contact:

Re: Can I require "package.file" instead of "package/file.lua"?

Post by willurd »

sroccaserra, I was having this problem too. Thanks a bunch for the loader!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Can I require "package.file" instead of "package/file.lua"?

Post by bartbes »

Ehm.. sorry to break it to you, but this functionally is part of love... (now)
Furthermore, you replied to a year-old thread, that's like humping a dead body! (joke, in case anyone gets offended)
User avatar
willurd
Citizen
Posts: 76
Joined: Thu Mar 04, 2010 1:04 am
Contact:

Re: Can I require "package.file" instead of "package/file.lua"?

Post by willurd »

Ah, I did, didn't I :)
matthewburk
Prole
Posts: 15
Joined: Fri Mar 05, 2010 6:56 am

Re: Can I require "package.file" instead of "package/file.lua"?

Post by matthewburk »

Please help, i am trying to make a package to use with love, but i have to add this

Code: Select all

package.path = '.\\?\\?.lua;' .. package.path
or my require fails. This only fails when running from a .love file.

Actually it seems my hack only works if i my .love file is in the same directory that its contents are in, if that makes any sense.
Attachments
cel.love
(903.14 KiB) Downloaded 120 times
User avatar
willurd
Citizen
Posts: 76
Joined: Thu Mar 04, 2010 1:04 am
Contact:

Re: Can I require "package.file" instead of "package/file.lua"?

Post by willurd »

matthewburk wrote:Please help, i am trying to make a package to use with love, but i have to add this

Code: Select all

package.path = '.\\?\\?.lua;' .. package.path
or my require fails. This only fails when running from a .love file.

Actually it seems my hack only works if i my .love file is in the same directory that its contents are in, if that makes any sense.
If I understand you correctly, I was having the same problem. I just switched from using dots to slashes, so for "my/file.lua", try this

Code: Select all

require("my/file")
instead of this

Code: Select all

require("my.file")
That fixed my problem.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Can I require "package.file" instead of "package/file.lua"?

Post by Robin »

matthewburk wrote:Actually it seems my hack only works if i my .love file is in the same directory that its contents are in, if that makes any sense.
It makes sense, because package.path is Lua's search path, not LÖVE's. For some reason, LÖVE still lets Lua handle require()s if it can't find the file itself.

So anything involving package.path is not going to work for your players.
Help us help you: attach a .love.
matthewburk
Prole
Posts: 15
Joined: Fri Mar 05, 2010 6:56 am

Re: Can I require "package.file" instead of "package/file.lua"?

Post by matthewburk »

Ok, i worked it out, although its not ideal. Basically I have to move the main module of my package outside of the folder for love to see it. All the submodules in the package can stay in the folder. It would be nice if love supporeted the main module in the package folder like stock lua. Makes distributing lua packages for love easier, and love is all about great distribution :P
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 5 guests