Lua searches the modules using the variable package.path
which in turn is started by reading a system variable called LUA_PATH
.
To add a new place to search for modules just change one of these variables.
If you want the folder to be always available you will want to edit the LUA_PATH
.
In Windows vc should go to System | Advanced System Settings | Environment Variables and add the LUA_PATH
or edit if it already exists. In Linux you will put this setup in your .bashrc
.
Ex:
LUA_PATH = ;;D:\libs\lua\?.lua
The ;;
at the beginning makes the moon load the default libs at the beginning of the path. Note that you have a query ?
in Pattern. It serves to mark the place where you will enter what you type in require.
Ex: Consider this directory structure:
D:
|- libs
|- lua
|- math
|- linearAlgebra.lua
With the LUA_PATH
defined as above you can do so in your moon code:
local la = require "math.linearAlgebra"
local v = la.dot({1, 0}, {1, 2})
...
The convention is to use a dot .
where there would be a directory separator (so math.linearAlgebra
and not math\\linearAlgebra
)
And also note that the .lua
is not specified as it has already been defined in LUA_PATH
.
If you want to add more search patterns, just separate them with ;
.
And finally it’s important to know that all of this also holds true for the package.path
.
You should not specify only the relative path of the file, in case
Lib\\BibliotecaPadrao
?– Woss
yes and did it, however it gives the same error q i think q eh prq just look in the same drive of the moon installed, and eh why I asked if it has how to say I want q look in the two drives or only in C:\
– user151959