0
votes

My understanding of require is as follows: If the file you are requiring is either in the same directory that you are requiring from, or is in package.path, you will be able to require it.

For me however, I get a Module not found! error, even when the files are in the same directory.

As for package.path, the directories listed do not exist on my PC. Here is my package.path:

/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;./?.lua

There are no folders named 'lua' on my PC (that I can find) other than ones created by me for different purposes. This leads me to suspect a bad install, although I did try to uninstall Lua and got Virtual packages like 'lua' can't be removed. This could be relevant, I'm not sure. But other than the inability to require modules and the lack of directories named 'lua', everything works fine.

At this point I'm not sure what to do. I can't find much information on the subject other than "append to your package.path!" but I would rather be able to simply have the two aforementioned files in the same directory for this to work.

How can I fix this?

I also have small question: Are there default modules/packages that come with lua?

1

1 Answers

0
votes

You don't provide enough information to help you, as you don't specify the version of Lua you're using (I guess 5.2 judging by the file path), the OS (Linux?), the actual require command you're executing or the location of the lua file you're requiring relative to the location of the file you're requiring it from, and so on.

Your assumptions are correct, but there may be multiple issues that would prevent you from loading the file. For example, it may be in the correct location, but instead of require "foo" you are using require "foo.lua", which is not going to work. Or you are trying to load a binary module (which is not going to be affected by package.path configuration). Or there is a dependency from the module you're loading that is not satisfied.

Are there default modules/packages that come with lua?

Yes, like debug, math, io, and others, but you won't see them as Lua files, as they are compiled as C modules together with the rest of the Lua interpreter.