]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Variant.sts
Added support for dynamically typed data access and a Variable interface.
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / Variant.sts
diff --git a/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Variant.sts b/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Variant.sts
new file mode 100644 (file)
index 0000000..745b3c3
--- /dev/null
@@ -0,0 +1,22 @@
+> import "Python"\r
+> a = variant ([1.0, 2.0, 3.0])\r
+> b = runPython do\r
+>     setPythonVariantVariable "foo" a\r
+>     executePythonStatement "foo.append(4.0)"\r
+>     getPythonVariantVariable "foo"\r
+> b\r
+[1.0 : Double, 2.0 : Double, 3.0 : Double, 4.0 : Double] : Variant[]\r
+> variantValue b :: [Double]\r
+[1.0, 2.0, 3.0, 4.0]\r
+> import "MMap" as MMap\r
+> runPython do\r
+>     foo = MMap.create () :: MMap.T String Dynamic\r
+>     MMap.put foo "c1" (toDynamic (vector [True, True, False, True]))\r
+>     MMap.put foo "c2" (toDynamic ["foo", "bar", "baz"])\r
+>     MMap.put foo "c3" (toDynamic 25.0)\r
+>     setPythonVariantVariable "foo" (variant foo)\r
+>     executePythonStatement "c1 = foo['c1']"\r
+>     executePythonStatement "c2 = foo['c2']"\r
+>     executePythonStatement "c3 = foo['c3']"\r
+>     (getPythonBooleanArrayVariable "c1", getPythonStringArrayVariable "c2", getPythonDoubleVariable "c3")\r
+(vector [True, True, False, True], vector ["foo", "bar", "baz"], 25.0)\r