-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
I've been looking into a better solution for the usage of require in bundled scripts and I've come up with the following plan:
- Add all bundled modules as package loaders.
- Remove the overridden
requirefunction and just use the standard one.
This should mean that the loading of any other modules (eg luasocket) will be unaffected by the bundling process.
There are two ways of directly including package loaders.
package.preload
package.preload["library.utils"] = package.preload["library.utils"] or function()
-- module contents...
endpackage.searchers
table.insert(package.loaders, function(package_name)
-- return module wrapped in function from here
end)By default, require looks for a package loader in the following order (according to package.searchers):
package.preloadpackage.pathpackage.cpath
That order can be changed by reordering the table or inserting a function earlier in the package.searchers table for loading bundled modules.
Let me know if you have any thoughts as to which option is better.
(Edited because I initially misread the manual)
Cc @rpatters1
Metadata
Metadata
Assignees
Labels
No labels