Updated docs for 'console' module and changed error message for failed require() to be more informative.

This commit is contained in:
walterhiggins 2013-12-28 12:12:45 +00:00
parent 76164254ba
commit a0ad7a8ec6
3 changed files with 29 additions and 4 deletions

View file

@ -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

View file

@ -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){

View file

@ -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)