lua-users home
lua-l archive

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


if type( package.config ) == "string" then
    local org_config = org_config or package.config

    local config = {};
    config.dirsep,
    config.pathsep,
    config.file_mark,
    config.execdir_mark,
    config.ignore_mark = table.unpack( org_config:split( "\n" ) ); -- split is one of those string funcs that lua really lacks, it's basically a simple gmatch( "()" .. seperator .. "()" ) loop

    package.config = setmetatable( config, { ["__tostring"] = function( tTable ) return org_config end } )
end

one time conversion, offers backwards compatibility (sort of) while offering the new method, same technique can be applied to the paths (this get's a bit easier if implemented natively instead)

The only drawback is that the string lib funcs don't check for __tostring (neither does the colon syntax when applied to a table), which is really a shame as it would give more weight to the metamethod

So in the end this won't work as well unless some other changes are done along with it, but hey, at least it's there...