]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/scl/Python.scl
Added support for dynamically typed data access and a Variable interface.
[simantics/python.git] / org.simantics.pythonlink / scl / Python.scl
index b1ca052ef2b026c3a3f00ebdcf05b2784e3962d8..5fc78318e62b88ce0f7fee4ed2b539613abec558 100644 (file)
@@ -1,5 +1,3 @@
-import "Vector"\r
-\r
 effect Python\r
     "Simantics/Python/Python"\r
     "org.simantics.pythonlink.PythonContext"\r
@@ -36,6 +34,27 @@ importJava "org.simantics.pythonlink.NDArray" where
     @JavaName equals\r
     ndarrayEquals :: NDArray -> NDArray -> Boolean\r
 \r
+class NDArrayInput a where\r
+    ndarrayInput :: a -> ([Integer], [Double])\r
+    \r
+instance NDArrayInput [Double] where\r
+    ndarrayInput v = ([length v], v)\r
+    \r
+instance (NDArrayInput [a]) => NDArrayInput [[a]] where\r
+    ndarrayInput v = let\r
+        inp = map ndarrayInput v\r
+        dims = map fst inp\r
+        vals = join $ map snd inp\r
+      in\r
+        if not (all (== (dims!0)) dims) then\r
+            fail "List of lists not of uniform dimension"\r
+          else\r
+            ([length v] + (dims!0), vals)\r
+\r
+ndarrayFromList :: NDArrayInput a => a -> NDArray\r
+ndarrayFromList v = ndarrayN (vector dims) (vector vals) where\r
+    (dims, vals) = ndarrayInput v\r
+\r
 instance Show NDArray where\r
     show = ndarrayToString\r
 \r
@@ -50,22 +69,35 @@ importJava "org.simantics.pythonlink.PythonContext" where
     \r
     executePythonStatement :: String -> <Python> ()\r
     \r
+    setPythonBooleanVariable :: String -> Boolean -> <Python> ()\r
     setPythonIntegerVariable :: String -> Integer -> <Python> ()\r
-    setPythonIntegerArrayVariable :: String -> Vector Integer -> <Python> ()\r
+    setPythonLongVariable :: String -> Long -> <Python> ()\r
     setPythonDoubleVariable :: String -> Double -> <Python> ()\r
-    setPythonDoubleArrayVariable :: String -> Vector Double -> <Python> ()\r
     setPythonStringVariable :: String -> String -> <Python> ()\r
+    \r
+    setPythonBooleanArrayVariable :: String -> Vector Boolean -> <Python> ()\r
+    setPythonIntegerArrayVariable :: String -> Vector Integer -> <Python> ()\r
+    setPythonLongArrayVariable :: String -> Vector Long -> <Python> ()\r
+    setPythonDoubleArrayVariable :: String -> Vector Double -> <Python> ()\r
     setPythonStringArrayVariable :: String -> Vector String -> <Python> ()\r
     setPythonNDArrayVariable :: String -> NDArray -> <Python> ()\r
     \r
+    getPythonBooleanVariable :: String -> <Python> Boolean\r
     getPythonIntegerVariable :: String -> <Python> Integer\r
-    getPythonIntegerArrayVariable :: String -> <Python> Vector Integer\r
+    getPythonLongVariable :: String -> <Python> Long\r
     getPythonDoubleVariable :: String -> <Python> Double\r
-    getPythonDoubleArrayVariable :: String -> <Python> Vector Double\r
     getPythonStringVariable :: String -> <Python> String\r
+    \r
+    getPythonBooleanArrayVariable :: String -> <Python> Vector Boolean\r
+    getPythonIntegerArrayVariable :: String -> <Python> Vector Integer\r
+    getPythonLongArrayVariable :: String -> <Python> Vector Long\r
+    getPythonDoubleArrayVariable :: String -> <Python> Vector Double\r
     getPythonStringArrayVariable  :: String -> <Python> Vector String\r
     getPythonNDArrayVariable :: String -> <Python> NDArray\r
     \r
+    setPythonVariantVariable :: String -> Variant -> <Python> ()\r
+    getPythonVariantVariable :: String -> <Python> Variant\r
+\r
 importJava "org.simantics.pythonlink.Python" where\r
     openPythonContext :: <Proc> PythonContext\r
     \r