Choosing require vs dofile in Lua: A Practical Decision Guide
Learn how to pick require or dofile for Lua modules, compare caching, error handling, and execution context, and see a concrete verification example.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how to pick require or dofile for Lua modules, compare caching, error handling, and execution context, and see a concrete verification example.
We maintain a Stylus-based component library where dozens of modules reference the same variables-and-mixins partial. The build compiles everything into one stylesheet through the Stylus CLI, and I need to pick a single inclusion convention for these shared dependencies. My understanding is that @import inlines the target file at every reference point, while
Lua caches loaded modules in package.loaded , and require returns the cached value without re-running the loader. The goal is to discard a broken or partially initialized module table after a failed upgrade and force a clean reload from disk. Invalidating package.loaded[modname] does not revoke references already held by other modules, so dependents may reta
I am trying to pin down the exact termination behavior of Lua's module search in package.path (assuming Lua 5.4). The manual documents that package.path holds semicolon-separated patterns with a ? placeholder replaced by the module name, and that require raises module 'foo' not found listing every attempted pattern. What it does not clearly state is whether