diff --git a/CommonJS/bin/press b/CommonJS/bin/press index 7db9a4137..9ad00a671 100755 --- a/CommonJS/bin/press +++ b/CommonJS/bin/press @@ -238,7 +238,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) { total++; totalBytes += aFileExecutable.code().length }, this); - stream.print(sprintf( + stream.print(ObjectiveJ.sprintf( "Saved \0green(%f%%\0) (\0blue(%s\0)); Total required files: \0magenta(%d\0) (\0blue(%s\0)) of \0magenta(%d\0) (\0blue(%s\0));", Math.round(((includedBytes - totalBytes) / totalBytes) * -100), bytesToString(totalBytes - includedBytes), diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 15e950a3b..21848040a 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -142,7 +142,7 @@ var CPStringRegexSpecialCharacters = [ [CPException raise:CPInvalidArgumentException reason:"initWithFormat: the format can't be 'nil'"]; - self = sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); + self = ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); return self; } @@ -158,7 +158,7 @@ var CPStringRegexSpecialCharacters = [ [CPException raise:CPInvalidArgumentException reason:"initWithFormat: the format can't be 'nil'"]; - return sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); + return ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); } /*! @@ -199,7 +199,7 @@ var CPStringRegexSpecialCharacters = [ if (!format) [CPException raise:CPInvalidArgumentException reason:"initWithFormat: the format can't be 'nil'"]; - return self + sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); + return self + ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); } /*! diff --git a/Objective-J/CPLog.js b/Objective-J/CPLog.js index a0f5765b5..8ad4ec238 100644 --- a/Objective-J/CPLog.js +++ b/Objective-J/CPLog.js @@ -82,7 +82,7 @@ function _CPLogDispatch(parameters, aLevel, aTitle) aLevel = CPLogDefaultLevel; // use sprintf if param 0 is a string and there is more than one param. otherwise just convert param 0 to a string - var message = (typeof parameters[0] == "string" && parameters.length > 1) ? sprintf.apply(null, parameters) : String(parameters[0]); + var message = (typeof parameters[0] == "string" && parameters.length > 1) ? exports.sprintf.apply(null, parameters) : String(parameters[0]); if (_CPLogRegistrations[aLevel]) for (var i = 0; i < _CPLogRegistrations[aLevel].length; i++) @@ -103,8 +103,8 @@ var _CPFormatLogMessage = function(aString, aLevel, aTitle) var now = new Date(); aLevel = ( aLevel == null ? '' : ' [' + aLevel + ']' ); - if (typeof sprintf == "function") - return sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s%s: %s", + if (typeof exports.sprintf == "function") + return exports.sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s%s: %s", now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds(), aTitle, aLevel, aString); diff --git a/Objective-J/CommonJS/lib/objective-j/loader.js b/Objective-J/CommonJS/lib/objective-j/loader.js index 7b7c38583..8d162d420 100644 --- a/Objective-J/CommonJS/lib/objective-j/loader.js +++ b/Objective-J/CommonJS/lib/objective-j/loader.js @@ -1,14 +1,14 @@ -var objj = null; function ObjectiveJLoader() { var loader = {}; var factories = {}; loader.reload = function(topId, path) { - if (!objj) objj = require("objective-j"); + if (!global.ObjectiveJ) + global.ObjectiveJ = require("objective-j"); //print("loading objective-j: " + topId + " (" + path + ")"); - factories[topId] = objj.make_narwhal_factory(path); + factories[topId] = ObjectiveJ.make_narwhal_factory(path); factories[topId].path = path; } diff --git a/Objective-J/Debug.js b/Objective-J/Debug.js index 1e154b109..27af496b9 100644 --- a/Objective-J/Debug.js +++ b/Objective-J/Debug.js @@ -24,12 +24,12 @@ function objj_debug_object_format(aReceiver) { - return (aReceiver && aReceiver.isa) ? sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver._UID) : String(aReceiver); + return (aReceiver && aReceiver.isa) ? exports.sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver._UID) : String(aReceiver); } function objj_debug_message_format(aReceiver, aSelector) { - return sprintf("[%s %s]", objj_debug_object_format(aReceiver), aSelector); + return exports.sprintf("[%s %s]", objj_debug_object_format(aReceiver), aSelector); } diff --git a/Objective-J/sprintf.js b/Objective-J/sprintf.js index 41071cbf3..d5df1b2a5 100644 --- a/Objective-J/sprintf.js +++ b/Objective-J/sprintf.js @@ -25,7 +25,7 @@ var formatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cbBdieEfgGosuxXpn%@])", "g"); var tagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cbBdieEfgGosuxXpn%@])"); -GLOBAL(sprintf) = function(format) +exports.sprintf = function(format) { var format = arguments[0], tokens = format.match(formatRegex), diff --git a/Tests/Objective-J/sprintfTest.j b/Tests/Objective-J/sprintfTest.j index 24c1696a3..b51bb7cd0 100644 --- a/Tests/Objective-J/sprintfTest.j +++ b/Tests/Objective-J/sprintfTest.j @@ -1,3 +1,4 @@ + // TODO: add many many more of these... var sprintfTestCases = [ [["[%@]", "hello world"], "[hello world]"], @@ -12,7 +13,7 @@ var sprintfTestCases = [ { for (var i = 0; i < sprintfTestCases.length; i++) { - [self assert:sprintf.apply(null, sprintfTestCases[i][0]) equals:sprintfTestCases[i][1]]; + [self assert:ObjectiveJ.sprintf.apply(null, sprintfTestCases[i][0]) equals:sprintfTestCases[i][1]]; } }