LuaRocks certainly has this functionality. See the “luarocks.loader” module. It comes with LuaRocks.
It will use the LuaRocks dependency information to determine who is asking for a module, and what versions it is compatible with. And then it will go off and actually return/load a compatible version.
Note that LuaRocks installs the modules in a file-tree that is searchable by Lua using the module environment variables, but it also has its own repository. So whenever a file is installed with the same name, the last one wins in the file-system. But in the repository they will remain available side-by-side. The LuaRocks loader is then smart enough to find the proper rock from the repository.
Make sure you require “luarocks.loader” before loading the other modules.