We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I made this little library: GitHub
I have put the Maven build of this library into my code
folder, and tried this:
import iliquid.exjs.*;
exJS js;
void setup() {
js = new exJS();
noLoop();
}
void draw() {
js.loadScript(sketchPath() + "/data/script.js");
js.addImport("java.lang.System", "system");
js.initEngine();
js.evalScript();
}
But I am getting errors like:
The function "loadScript(String)" doesn't exist
even though the function clearly exists in my library's code:
public void loadScript(String path) {
try {
script = new BufferedReader(new FileReader(path));
} catch (FileNotFoundException e) {
System.err.printf("(exJS) Error: Could not load script from file %s%n", path);
e.printStackTrace();
}
}
You might suggest that I should use the Eclipse Library Template. I don't want to, because I use IntelliJ (although it has an Eclipse project import feature, but this didn't happen with a previous library of mine, which was developed without the template like this one.)
What could be the cause of my problem?
Answers
I've copied file "exJS.java" and pasted it into the PDE as a ".java" tab:
https://Raw.GitHubUserContent.com/liquid600pgm/lib_exJavaScript/master/src/main/java/iliquid/exjs/exJS.java
Created a "script.js" inside subfolder "data/" w/ just this simple statement:
print('Nashorn')
.Made some tiny changes to your posted code. And voilà, it's just worked: \m/
classes traditionally start with a Capital letter
Just so you know, I've also made some utility functions for Nashorn: O:-)
https://Forum.Processing.org/two/discussion/15151/how-to-convert-string-to-a-line-of-code#Item_9
Out of curiosity, I've tried to comment out my import statement, and it seems like
exJS
is an already existing class somewhere. I will have to rename my class then.EDIT: I am so stupid. I totally forgot that Processing adds
class SketchName { ...
behind the scenes, and I called my sketchexJS
. That was not a very smart idea.Yes, naming the sketch the same thing as the class has bit me a number of times in the past.
It is too bad that PDE can't check for that at compile time and do a magic rename if there is a collision -- although adding more magic could then create further, even more obscure problems.