1
1
Class isc .py .Callout
2
2
{
3
3
4
+ Parameter PyLibId As Integer = 4937 ;
5
+
6
+ Parameter Initialize As Integer = 1 ;
7
+
8
+ Parameter Finalize As Integer = 2 ;
9
+
10
+ Parameter GetRandom As Integer = 3 ;
11
+
12
+ Parameter GetRandomSimple As Integer = 4 ;
13
+
14
+ Parameter SimpleStringFull As Integer = 5 ;
15
+
16
+ Parameter SimpleString As Integer = 6 ;
17
+
4
18
Parameter DLL As COSEXPRESSION = " $g(^isc.py.Callout, $g(^%SYS(" " bindir" " )) _ " " libhelloworld.dll" " )" ;
5
19
20
+ /// write ##class(isc.py.Callout).Setup()
21
+ ClassMethod Setup ()
22
+ {
23
+ set sc = $ZF (-4 ,6 ,..#PyLibId)
24
+ set sc = $ZF (-4 ,5 ,..#PyLibId, ..#DLL)
25
+ quit sc
26
+ }
27
+
6
28
/// Init Python context
7
29
/// do ##class(isc.py.Callout).Initialize()
8
- ClassMethod Initialize () As %Integer
30
+ ClassMethod Initialize (debug As %Boolean = {$$$NO} ) As %Integer
9
31
{
10
- set path = ..#DLL
11
- do $ZF (-3 , path , " Initialize" )
32
+ if debug {
33
+ set sc = $ZF (-4 ,4 ,..#PyLibId) // unload current copy of inputlib
34
+ set sc = $ZF (-4 ,8 ) // delete existing process index, if any
35
+ set sc = $ZF (-4 ,7 ,..#PyLibId, ..#DLL) // override system index
36
+ }
37
+ do $ZF (-6 , ..#PyLibId, ..#Initialize)
12
38
}
13
39
14
40
/// Test method. Get random number
15
41
/// w ##class(isc.py.Callout).GetRandom()
16
42
ClassMethod GetRandom () As %Double
17
43
{
18
- set path = ..#DLL
19
- set random = $ZF (-3 , path , " GetRandom" )
44
+ set random = $ZF (-6 , ..#PyLibId, ..#GetRandom)
20
45
quit random
21
46
}
22
47
23
48
/// Test method. Get random number
24
49
/// w ##class(isc.py.Callout).GetRandomSimple()
25
50
ClassMethod GetRandomSimple () As %Double
26
51
{
27
- set path = ..#DLL
28
- set random = $ZF (-3 , path , " GetRandomSimple" )
52
+ set random = $ZF (-6 , ..#PyLibId, ..#GetRandomSimple)
29
53
quit random
30
54
}
31
55
@@ -39,7 +63,7 @@ ClassMethod SimpleStringFull(code = {"import random;" _ $$$NL _ "x=random.random
39
63
set converted = $$$YES
40
64
}
41
65
set path = ..#DLL
42
- set result = $ZF (-3 , path , " SimpleStringFull" , code )
66
+ set result = $ZF (-6 , ..#PyLibId, ..# SimpleStringFull, code )
43
67
set :converted result = $zcvt (result , " I" , " UTF8" )
44
68
quit result
45
69
}
@@ -55,7 +79,7 @@ ClassMethod SimpleString(code As %String = {"import random;" _ $$$NL _ "x=random
55
79
set converted = $$$YES
56
80
}
57
81
set path = ..#DLL
58
- set result = $ZF (-3 , path , " SimpleString" , code , variable )
82
+ set result = $ZF (-6 , ..#PyLibId, ..# SimpleString, code , variable )
59
83
60
84
set :converted result = $zcvt (result , " I" , " UTF8" )
61
85
quit result
@@ -66,14 +90,14 @@ ClassMethod SimpleString(code As %String = {"import random;" _ $$$NL _ "x=random
66
90
ClassMethod Finalize () As %Integer
67
91
{
68
92
set path = ..#DLL
69
- do $ZF (-3 , path , " Finalize" )
93
+ do $ZF (-6 , ..#PyLibId, ..# Finalize)
70
94
}
71
95
72
96
/// Unload library
73
97
/// write ##class(isc.py.Callout).Unload()
74
98
ClassMethod Unload () As %Integer
75
99
{
76
- set result = $ZF (-3 , " " )
100
+ set result = $ZF (-4 , 4 , ..#PyLibId )
77
101
quit result
78
102
}
79
103
0 commit comments