-
Notifications
You must be signed in to change notification settings - Fork 150
Nathan Jensen edited this page Sep 7, 2015
·
28 revisions
- We haven't tried it yet. In theory it should possible, but there may be some challenges to overcome. If you try this, we'd love to hear about it and will gladly accept contributions to make Jep work well on more platforms.
- Jep should work with any pure python modules. Unfortunately, CPython extensions and Cython modules may not work correctly, it depends on how they were coded. We have started a list of Package Compatibility. Please contribute to the list with your findings.
- Jep has been run with Swing and SWT. We haven't tried JavaFX yet, but it should work.
try(Jep jep = new Jep(false)) {
jep.eval("import somePyModule");
// any of the following work, these are just pseudo-examples
// using eval(String) to invoke methods
jep.setValue("arg", obj);
jep.eval("x = somePyModule.foo1(arg)");
Object result1 = jep.getValue("x");
// using getValue(String) to invoke methods
Object result2 = jep.getValue("somePyModule.foo2()");
// using invoke to invoke methods
Object result3 = jep.invoke("somePyModule.foo3", obj);
// using runScript
jep.runScript("path/To/Script");
}
-
eval(String)
was originally written to support interactive mode or non-interactive mode (multiple statements or a single statement, see javadoc), so the boolean return value is whether or not the statement was actually executed. There is also an overhead of always returning the result, especially if code is making multiple calls to eval(String) and doesn't need the results. To change the method signature now would potentially break compatibility with a number of applications. -
getValue(String)
is almost identical in the C code toeval(String)
and will return the result of the evaluation, and can be used instead of eval where desired. For example:
// evaluates and discards the result
jep.eval("2 + 4");
// evaluates and places the results in x
jep.eval("x = 2 + 4");
Integer x = (Integer) jep.getValue("x");
// evaluates and returns the results
Integer y = (Integer) jep.getValue("2 + 4");