if (args.length != 1) {
throw Context.reportRuntimeError(
"addToClasspath() requires one argument");
}
try {
Trackable path;
RhinoEngine engine = ((RingoGlobal) funObj.getParentScope()).engine;
Object arg = args[0] instanceof Wrapper ?
((Wrapper) args[0]).unwrap() : args[0];
if (arg instanceof String) {
path = engine.resolve((String) arg,
engine.getParentRepository(thisObj));
} else if (arg instanceof Trackable) {
path = (Trackable) arg;
} else {
throw Context.reportRuntimeError(
"addToClasspath() requires a path argument");
}
if (!path.exists()) {
throw Context.reportRuntimeError("addToClasspath(): Cannot find " + path);
}
engine.addToClasspath(path);
return Boolean.TRUE;