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

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

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

sroccaserra, I was having this problem too. Thanks a bunch for the loader!

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"?

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)

willurd
Citizen
Posts: 76
Joined: Thu Mar 04, 2010 1:04 am
Contact:

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

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"?

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

willurd
Citizen
Posts: 76
Joined: Thu Mar 04, 2010 1:04 am
Contact:

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

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")

Code: Select all

require("my.file")
That fixed my problem.

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"?

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.