From a0ad7a8ec6dd53f91ebd96a7cee83b73c1a33336 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Sat, 28 Dec 2013 12:12:45 +0000 Subject: [PATCH] Updated docs for 'console' module and changed error message for failed require() to be more informative. --- docs/API-Reference.md | 12 +++++++++++- src/main/javascript/lib/console.js | 12 +++++++++++- src/main/javascript/lib/require.js | 9 +++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index b815b92..e03d9b6 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -524,7 +524,7 @@ ScriptCraft provides a `console` global variable with the followng methods... * warn() * error() -The ScriptCraft console methods work like the Web API implementation. +The ScriptCraft console methods work like the [Web API implementation][webcons]. ### Example @@ -536,8 +536,18 @@ uses [java.lang.String.format()][strfmt] for variable substitution. All output will be sent to the server console (not in-game). +### Using string substitutions + +ScriptCraft uses Java's [String.format()][strfmt] so any string substitution identifiers supported by +`java.lang.String.format()` are supported (e.g. %s , %d etc). + + for (var i=0; i<5; i++) { + console.log("Hello, %s. You've called me %d times.", "Bob", i+1); + } + [lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html [strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...) +[webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console ## http.request() function diff --git a/src/main/javascript/lib/console.js b/src/main/javascript/lib/console.js index 77c27bd..e865221 100644 --- a/src/main/javascript/lib/console.js +++ b/src/main/javascript/lib/console.js @@ -8,7 +8,7 @@ ScriptCraft provides a `console` global variable with the followng methods... * warn() * error() -The ScriptCraft console methods work like the Web API implementation. +The ScriptCraft console methods work like the [Web API implementation][webcons]. ### Example @@ -20,8 +20,18 @@ uses [java.lang.String.format()][strfmt] for variable substitution. All output will be sent to the server console (not in-game). +### Using string substitutions + +ScriptCraft uses Java's [String.format()][strfmt] so any string substitution identifiers supported by +`java.lang.String.format()` are supported (e.g. %s , %d etc). + + for (var i=0; i<5; i++) { + console.log("Hello, %s. You've called me %d times.", "Bob", i+1); + } + [lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html [strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...) +[webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console ***/ var argsToArray = function(args){ diff --git a/src/main/javascript/lib/require.js b/src/main/javascript/lib/require.js index e6e5847..1cd1677 100644 --- a/src/main/javascript/lib/require.js +++ b/src/main/javascript/lib/require.js @@ -187,7 +187,12 @@ When resolving module names to file paths, ScriptCraft uses the following rules. { var file = resolveModuleToFile(path, parentFile); if (!file){ - throw new Error("require('" + path + "'," + parentFile.canonicalPath + ") failed"); + var errMsg = java.lang.String + .format("require() failed to find matching file for module '%s' " + + "while searching directory '%s' and paths %s.", + [path, parentFile.canonicalPath, JSON.stringify(modulePaths)]); + console.warn(errMsg); + throw new Error(errMsg); } var canonizedFilename = _canonize(file); @@ -237,7 +242,7 @@ When resolving module names to file paths, ScriptCraft uses the following rules. .apply(moduleInfo.exports, /* this */ parameters); } catch (e){ - logger.severe("Error:" + e + " while executing module " + canonizedFilename); + console.error("Error:" + e + " while executing module " + canonizedFilename); throw e; } if (verbose)