What's the difference between require and include in torch(lua)? what it did in the back when we call include or require? for example:
include('util/test.lua')
require('util/test.lua')
in require if the compiler cannot find the specific file compiler will stop to compile other part off the code
but in include if the compiler cant find the file ,begin to compile other parts of code with no errror
Torch include is simply Lua dofile as can be seen in the Torch source:
function torch.include(package, file)
dofile(torch.packageLuaPath(package) .. '/' .. file)
end
On the other hand, Lua require is used to load modules. Also see this answer.
Roughly, require does the same job as dofile, but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work. Because of these features, require is the preferred function in Lua for loading libraries.