/**
 * Compile less string.
 * @function lib.compile.compileLessString
 * @see {@link http://www.lesscss.org/ | less }
 * @param {string} src - Source less string.
 * @param {object} options - Compile options.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */


exports = module.exports = function (src, options, callback) {
    switch (arguments.length) {
        case 2:
            if (typeof(arguments[1]) === 'function') {
                callback = arguments[1];
            }
            break;
    }

    var less = require('less');
    try {
        new less
            .Parser(options || {})
            .parse(src, function (err, tree) {
                if (err) {
                    callback(exports._errMsgString(err));
                    return;
                }
                var compiled = tree.toCSS();
                callback(null, compiled);
            });

    } catch (e) {
        callback(e);
    }

};


exports._errMsgString = function (err) {
    if (typeof(err) === 'string') {
        return err;
    }
    return JSON.stringify(err, null, 4);
};