]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java
Some fixes to Python integration.
[simantics/python.git] / org.simantics.pythonlink / src / org / simantics / pythonlink / PythonContext.java
index d237c83eb5afd5ab0c112111adaadeb2120b729e..5341cc233c16c02076e00bbfa8684aa09d14c001 100644 (file)
@@ -6,19 +6,27 @@ public class PythonContext implements Closeable {
     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
@@ -39,6 +47,8 @@ public class PythonContext implements Closeable {
     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
@@ -68,10 +78,10 @@ public class PythonContext implements Closeable {
     }\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