3 ms·
So now that module(...) is deprecated does anyone know the expected standard pattern? The changes say to just build it with code (setting _ENV?) but do the devs
by Avshalom 15y ago
So now that module(...) is deprecated does anyone know the expected standard pattern? The changes say to just build it with code (setting _ENV?) but do the devs have a "right way" to do it?
- LeafStorm 15y agoThe Lua developers are generally not very fond of endorsing a single "right way" to do things. But basically, it's something like: -- localize all the stuff you need local _ENV = {} -- module code return _ENV So really not that much code to add yourself.
- compay 15y agoAn easy way is to just define your functions in a table, and at the end of the file to be required, return the table. This was the pattern used in Lua before 5.1. The source for Luacov provides a clear example: https://github.com/keplerproject/luacov/blob/master/src/luacov.lua https://github.com/keplerproject/luacov/blob/master/src/luac...