]> gerrit.simantics Code Review - simantics/python.git/blob - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts
Added support for dynamically typed data access and a Variable interface.
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / Python.sts
1 > import "Python"\r
2\r
3 > runPython do\r
4 >     executePythonStatement "foo = 'bar'\nd = dir()"\r
5 >     getPythonStringArrayVariable "d"\r
6 vector ["__builtins__", "__doc__", "__loader__", "__name__", "__package__", "__spec__", "foo"]\r
7 > runPython do\r
8 >     getPythonStringVariable "__name__"\r
9 "SCL_2"\r
10 > runPython do\r
11 >     setPythonDoubleVariable "foo" 1\r
12 >     executePythonStatement "foo = foo + 1"\r
13 >     getPythonDoubleVariable "foo"\r
14 2.0\r
15 > runPython do\r
16 >     setPythonDoubleArrayVariable "foo" (vector [1.0, 2.0, 3.0])\r
17 >     executePythonStatement "foo = foo + [4.0]"\r
18 >     getPythonDoubleArrayVariable "foo"\r
19 vector [1.0, 2.0, 3.0, 4.0]\r
20 > runPython do\r
21 >     setPythonIntegerVariable "foo" 5\r
22 >     executePythonStatement "import math"\r
23 >     executePythonStatement "bar = math.factorial(foo)"\r
24 >     getPythonIntegerVariable "bar"\r
25 120\r
26 > runPython do\r
27 >     setPythonIntegerArrayVariable "foo" (vector [1, 2, 3, 4])\r
28 >     executePythonStatement "foo.append(sum(foo))"\r
29 >     getPythonIntegerArrayVariable "foo"\r
30 vector [1, 2, 3, 4, 10]\r
31 > runPython do\r
32 >     setPythonBooleanVariable "foo" False\r
33 >     executePythonStatement "foo = not(foo)"\r
34 >     getPythonBooleanVariable "foo"\r
35 True\r
36 > runPython do\r
37 >     setPythonVariable "foo" ([1.0, 2.0, 3.0, 4.0] :: [Double])\r
38 >     executePythonStatement "foo.append(sum(foo))"\r
39 >     getPythonVariable "foo" :: [Double]\r
40 [1.0, 2.0, 3.0, 4.0, 10.0]\r
41 > py = openPythonContext\r
42 > runWithPythonContext py $ setPythonIntegerVariable "foo" 4\r
43 > runWithPythonContext py $ setPythonDoubleArrayVariable "bar" (vector [1.0, 2.0, 3.0])\r
44 > runWithPythonContext py $ executePythonStatement "bar.append(float(foo))"\r
45 > bar = runWithPythonContext py $ getPythonDoubleArrayVariable "bar"\r
46 > closePythonContext py\r
47 > bar\r
48 vector [1.0, 2.0, 3.0, 4.0]\r