private long contextID;\r
\r
PythonContext() {\r
- contextID = openPythonContextImpl();\r
+ contextID = createContextImpl();\r
}\r
\r
@Override\r
public void close() {\r
long id = contextID;\r
contextID = 0;\r
- closePythonContextImpl(id);\r
+ if (id != 0) deleteContextImpl(id);\r
+ }\r
+\r
+ @Override\r
+ protected void finalize() throws Throwable {\r
+ super.finalize();\r
+ close();\r
}\r
\r
public void executePythonStatement(String statement) {\r
executePythonStatementImpl( contextID, statement );\r
}\r
+\r
+ // Setters\r
\r
public void setPythonIntegerVariable(String variableName, int value) {\r
setPythonIntegerVariableImpl(contextID, variableName, value);\r
public void setPythonStringArrayVariable(String variableName, String[] value) {\r
setPythonStringArrayVariableImpl(contextID, variableName, value);\r
}\r
+\r
+ // Getters\r
\r
public int getPythonIntegerVariable(String variableName) {\r
return getPythonIntegerVariableImpl(contextID, variableName);\r
}\r
\r
// Native function declarations\r
- private static native long openPythonContextImpl();\r
- private static native void closePythonContextImpl(long contextID);\r
+ private static native long createContextImpl();\r
+ private static native void deleteContextImpl(long contextID);\r
\r
- private static native void executePythonStatementImpl(long contextID, String statement);\r
+ private static native int executePythonStatementImpl(long contextID, String statement);\r
\r
private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value);\r
private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);\r