Skip to content

Commit 34164eb

Browse files
committed
Moved to efficient $zf(-6) calls.
Fixed #9
1 parent b944dbc commit 34164eb

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

isc/py/Callout.cls

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
11
Class isc.py.Callout
22
{
33

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+
418
Parameter DLL As COSEXPRESSION = "$g(^isc.py.Callout, $g(^%SYS(""bindir"")) _ ""libhelloworld.dll"")";
519

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+
628
/// Init Python context
729
/// do ##class(isc.py.Callout).Initialize()
8-
ClassMethod Initialize() As %Integer
30+
ClassMethod Initialize(debug As %Boolean = {$$$NO}) As %Integer
931
{
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)
1238
}
1339

1440
/// Test method. Get random number
1541
/// w ##class(isc.py.Callout).GetRandom()
1642
ClassMethod GetRandom() As %Double
1743
{
18-
set path = ..#DLL
19-
set random = $ZF(-3, path, "GetRandom")
44+
set random = $ZF(-6, ..#PyLibId, ..#GetRandom)
2045
quit random
2146
}
2247

2348
/// Test method. Get random number
2449
/// w ##class(isc.py.Callout).GetRandomSimple()
2550
ClassMethod GetRandomSimple() As %Double
2651
{
27-
set path = ..#DLL
28-
set random = $ZF(-3, path, "GetRandomSimple")
52+
set random = $ZF(-6, ..#PyLibId, ..#GetRandomSimple)
2953
quit random
3054
}
3155

@@ -39,7 +63,7 @@ ClassMethod SimpleStringFull(code = {"import random;" _ $$$NL _ "x=random.random
3963
set converted = $$$YES
4064
}
4165
set path = ..#DLL
42-
set result = $ZF(-3, path, "SimpleStringFull", code)
66+
set result = $ZF(-6, ..#PyLibId, ..#SimpleStringFull, code)
4367
set:converted result = $zcvt(result, "I", "UTF8")
4468
quit result
4569
}
@@ -55,7 +79,7 @@ ClassMethod SimpleString(code As %String = {"import random;" _ $$$NL _ "x=random
5579
set converted = $$$YES
5680
}
5781
set path = ..#DLL
58-
set result = $ZF(-3, path, "SimpleString", code, variable)
82+
set result = $ZF(-6, ..#PyLibId, ..#SimpleString, code, variable)
5983

6084
set:converted result = $zcvt(result, "I", "UTF8")
6185
quit result
@@ -66,14 +90,14 @@ ClassMethod SimpleString(code As %String = {"import random;" _ $$$NL _ "x=random
6690
ClassMethod Finalize() As %Integer
6791
{
6892
set path = ..#DLL
69-
do $ZF(-3, path, "Finalize")
93+
do $ZF(-6, ..#PyLibId, ..#Finalize)
7094
}
7195

7296
/// Unload library
7397
/// write ##class(isc.py.Callout).Unload()
7498
ClassMethod Unload() As %Integer
7599
{
76-
set result = $ZF(-3, "")
100+
set result = $ZF(-4, 4, ..#PyLibId)
77101
quit result
78102
}
79103

0 commit comments

Comments
 (0)