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 » Mon Mar 08, 2010 6:11 pm

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 » Mon Mar 08, 2010 6:14 pm

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 » Tue Mar 09, 2010 7:44 am

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 » Wed Mar 17, 2010 8:27 am

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 73 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 » Wed Mar 17, 2010 9:45 am

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 » Wed Mar 17, 2010 8:42 pm

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 » Thu Mar 18, 2010 7:36 am

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: No registered users and 26 guests