lua-users home
lua-l archive

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



On Mar 19, 2008, at 9:27 AM, Duck wrote:

which also means that the module needn't actually get require()ed unless and until it is wanted.

Indeed a rather useful idiom I find myself using quiet often: instead of importing everything upfront, only do so when needed.

For example:

function IndexLink( aPrefix )
    local HTTPExtra = require( 'HTTPExtra' )
    local HTTPService = require( 'HTTPService' )
    local WikiIndexService = require( 'WikiIndexService' )
    local aFirst, aSecond = ( aPrefix or '' ):match( '^(%w)(%w?)' )
    local aService = WikiIndexService( aFirst, aSecond )
    local aURL = HTTPService[ aService ]

    return aURL.path
end

--
PA.
http://alt.textdrive.com/nanoki/