Page 1 of 1

The require() function.

Posted: Fri Jan 04, 2013 1:50 am
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
]

Re: The require() function.

Posted: Fri Jan 04, 2013 2:32 am
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.

Re: The require() function.

Posted: Fri Jan 04, 2013 2:37 am
by Nah-Trowen
Thanks a lot, really helped!

Re: The require() function.

Posted: Fri Jan 04, 2013 8:09 am
by Jasoco
You can also simplify it to just:

Code: Select all

require "char"

Re: The require() function.

Posted: Tue Oct 22, 2013 9:35 pm
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?

Re: The require() function.

Posted: Tue Oct 22, 2013 11:07 pm
by Ref
Provide a Love file and we'll see.
Best

Re: The require() function.

Posted: Wed Oct 23, 2013 8:07 pm
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

Re: The require() function.

Posted: Wed Oct 23, 2013 9:29 pm
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.

Re: The require() function.

Posted: Wed Oct 23, 2013 10:47 pm
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