lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Oct 19, 2011 at 6:48 AM, Doug Currie <doug.currie@gmail.com> wrote:
>
> On Oct 18, 2011, at 1:53 AM, David Manura wrote:
>
>> On Mon, Oct 17, 2011 at 1:00 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
>>> Now we are trying to support two ways, check out this code at about line 60:
>>>  https://github.com/dcurrie/lunit/blob/master/lunit.lua
>>
>> That's ugly, though not necessary either.  I would, like Luiz, avoid
>> using both _ENV and 'module' for module definition.
>
> Of course it's not necessary for new modules. I avoid both _ENV and 'module' for any new modules I create. The challenge is trying to maintain maximum compatibility with uses of existing modules, such as lunit, in large code bases, with both Lua 5.1 and 5.2.
>
> e
>
>
>

It's really not that hard though, replace the module call with a table
creation, do a find and replace of non-local definitions prefixing
with the table name and then return the table at the end. You now
support everything. Calling code just needs to change from require 'a'
to local a = require 'a'.

What's more you don't have to do it all at once either, a module at a
time works fine.