The require() function.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Nah-Trowen
Prole
Posts: 8
Joined: Thu Jan 03, 2013 8:04 am

The require() function.

Post by Nah-Trowen »

Every time I run my project it gives me the error message :

Error

main.lua:1:module 'char.lua' not found:
no file "char/lua.lua" in LOVE game directories.

no extension"char.lua" in LOVE paths.

not field package.preload['char.lua']
no file '.\char\lua.lua
no file 'C:\Program Files\LOVE\lua\char\lua.lua'
no file 'C:\Program Files\LOVE\lua\char\lua\init.lua'
no file 'C:\Program Files\LOVE\char\lua.lua'
no file 'C:\Program Files\LOVE\char\lua\init.lua
no file 'C:\Program Files\Lua\5.1\lua\char\lua.luac'
no file '.\char\lua.dll'
no file 'C:\Program Files\LOVE\char\lua.dll'
no file 'C:\Program Files\LOVE\loadall.dll'
no file '.\char.dll'
no file 'C:\Program Files\LOVE\char.dll'
no file 'C:\Program Files\LOVE\cloadall.dll'

Traceback

[C]: in function 'require'

Code: Select all

require("char.lua")

function love.load()
love.graphics.setBackgroundColor(255,255,255)
end

function love.draw()	
	charDraw()
end

function love.update()
end
]
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: The require() function.

Post by Qcode »

Remove the .lua in the require function. So just require("char"). The "." Symbolizes a folder, so the program is looking inside the "char" folder for a file called Lua. You can see how that error is happening in the second line of error code.
Nah-Trowen
Prole
Posts: 8
Joined: Thu Jan 03, 2013 8:04 am

Re: The require() function.

Post by Nah-Trowen »

Thanks a lot, really helped!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: The require() function.

Post by Jasoco »

You can also simplify it to just:

Code: Select all

require "char"
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: The require() function.

Post by McPandaBurger »

Hi,

I know this is a pretty old thread, but I'm getting the same issue in 0.8

using this as the post above described

Code: Select all

require "cam" --Should pull in the camera code...in theory anyway
and I get this:
Error: main.lua:1: module 'cam' not found:
no file "cam.lua" in LOVE game directories.

no extension "cam" in LOVE paths.

no field package.preload['cam']
no file '.\cam.lua'
no file 'c:\Program Files (x86)\love\lua\cam.lua'
no file 'c:\Program Files (x86)\love\lua\cam\init.lua'
no file 'c:\Program Files (x86)\love\cam.lua'
no file 'c:\Program Files (x86)\love\cam\init.lua'
no file '.\cam.dll'
no file 'c:\Program Files (x86)\love\cam.dll'
no file 'c:\Program Files (x86)\love\loadall.dll'
stack traceback:
[C]: in function 'require'
main.lua:1: in main chunk
[C]: in function 'require'
[string "boot.lua"]:331: in function <[string "boot.lua"]:227>
[C]: in function 'xpcall'

the cam file is right next to the main.lua so I can't work out what I'm doing wrong, does anyone have any ideas?
I have no idea what I'm doing
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: The require() function.

Post by Ref »

Provide a Love file and we'll see.
Best
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: The require() function.

Post by McPandaBurger »

oops forgot to do that.

So things to know, I'm new to this and currently that folder doesn't make much sense feel free to point out anything I might be doing wrong even if it's not related I'm happy to learn anything you want to offer. and just ask if something isn't clear.

cheers

Dan
Attachments
Game1.love
(30.42 KiB) Downloaded 282 times
I have no idea what I'm doing
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: The require() function.

Post by Boolsheet »

You should call your files cam.lua and conf.lua.

The require function takes a module name and the LÖVE and Lua loaders try different things with this name until they find something. For example, they try to add .lua to the module name and look in various directories. Or they add .so or .dll and look for a binary module. Or they use the module name as a directory name and load init.lua if it exists in there.
Shallow indentations.
User avatar
McPandaBurger
Prole
Posts: 16
Joined: Sat Apr 28, 2012 3:32 pm

Re: The require() function.

Post by McPandaBurger »

Thanks dude, I thought I had done that but yeah looking at the the extensions I see I hadn't, nice spot thanks for your help
I have no idea what I'm doing
Post Reply

Who is online

Users browsing this forum: No registered users and 71 guests