@Andrew_Stacey: Aha! I think I’ve sorted out a way to make this workable. Tell me what you think of this proposal:
a) cmodule will provide an API for specifying the search path. You’ll pass it a table/variable argument list of projects that you want to be in the search path:
-- set path
cmodule.path{"SomeProject", "SomeOtherProject", "Whatever", "Utilities"}
-- or --
cmodule.path("SomeProject", "SomeOtherProject", "Whatever", "Utilities")
-- get a table listing the projects currently in the path
local cpath = cmodule.path()
This API has the feature (whether this is for better or for worse remains to be seen) of allowing you to modify cmodule’s search path anytime during runtime, since you can get the search path table, modify it, and give it back to cmodule.path(). If that feature is not desirable or provides too much flexibility, I could simply throw an error if more than 1 attempt is made to set the path during program execution.
b) All of the cmodule APIs will continue to do what they do now, which is attempt to load/introspect using the “default” project (the currently running project if you called _G.cimport/cmodule.import, or the owning project if you called cimport from within a module); if the module is not found there, then it will check to see if a search path is defined. If not, it will throw a “module not found” error. If so, cmodule will search the projects in the path in the order they were passed to cmodule.path, and will use the first matching module name it finds. If the module name is not found in any of those projects, it will throw a “module not found” error.
This way, cimport/cload suffers no additional overhead for the common use case, since we only search if the module is not found in the default project, while still allowing more generic/flexible usage of the cmodule library for more special cases.
I’m still a bit concerned that this will make it harder to reason about code that uses this feature, since it will not be obvious simply from reading a module’s code where the modules it depends on are located, but pragmatically speaking this is probably the best solution.
EDIT: this is completely workable. I’m about halfway done implementing it, but I probably won’t get to hack on it anymore today. Hopefully by tomorrow evening or sometime Monday I’ll have cmodule updated to 0.1.0, with the search path feature included.