lua-users home
lua-l archive

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


On Oct 19, 2011, at 7:20 PM, Hisham wrote:

> Well noted. Doing this gets us the following:

Alternatively, perhaps this can be boiled down to something along these lines:

function module( aName, ... )
    local aModule = package.loaded[ aName ]
    
    if type( aModule ) ~= 'table' then
        aModule = {}
        aModule._M = aModule
        aModule._NAME = aName
        aModule._PACKAGE = aName:sub( 1, aName:len() - ( aName:reverse():find( '.', 1, true ) or 0 ) )
        
        package.loaded[ aName ] = aModule
        
        for anIndex = 1, select( '#', ... ) do
            select( anIndex, ... )( aModule )
        end
    end

    return aModule
end


http://dev.alt.textdrive.com/browser/HTTP/debugx.lua#L79