|
On 10/16/2016 10:52 AM, Laurent FAILLIE wrote:
That is a link to the free on-line copy of PiL that is out of date in some details. It was written for Lua 5.0, and one of the biggest areas of change between 5.0 and 5.1 was in the module system. Best practices for modules have continued to evolve since then, while remaining generally backward compatible to Lua 5.1. If you are heavily invested in a Lua 5.1 code base that won't be upgrading any time soon, I'd highly recommend finding a copy of the Second Edition of PiL which was updated specifically to track changes for Lua 5.1. It is apparently still available both in print and as an eBook. My print copy is well worn at this point. https://www.lua.org/pil/
The true story for Lua 5.1 is in the reference manual, admittedly scattered about a bit since each of the moving parts has its own section. The module system is covered by section 5.3. https://www.lua.org/manual/5.1/manual.html#5.3 The details of what the predefined package searchers do, and exactly where they look for information to guide their search is in the documentation of the package.loaders[] array where searchers live. The searcher that looks for modules on a path is in package.loaders[2]. https://www.lua.org/manual/5.1/manual.html#pdf-package.loaders The module path (for modules written in Lua, to be precise) is found in package.path, which is initialized from a compiled in default which can be replaced by an environment variable. https://www.lua.org/manual/5.1/manual.html#pdf-package.path The large changes from 5.0 to 5.1 are documented in chapter 7, and the change to require and package.path is in 7.2. https://www.lua.org/manual/5.1/manual.html#7.2 -- Ross Berteig Ross@CheshireEng.com Cheshire Engineering Corp. http://www.CheshireEng.com/ +1 626 303 1602 |