You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Gateway.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,6 +172,41 @@ kill obj
172
172
set p1 = ##class(isc.py.gw.DynamicObject).%New(, "p1")
173
173
```
174
174
175
+
Module objects can be proxied this way too:
176
+
177
+
```
178
+
set module = "random"
179
+
set sc = ##class(isc.py.Main).ImportModule(module)
180
+
set random = ##class(isc.py.gw.DynamicObject).%New(,module)
181
+
write random.randint(1,100)
182
+
```
183
+
184
+
Now for a more complex example. In case of primitives (int, bool, str, float) proxy object returns a serialized value. Otherwise (if method call or variable get returns complex type) it returns another proxy object pointing to that result.
185
+
186
+
```
187
+
set sc = ##class(isc.py.Main).ImportModule("numpy",,"np")
188
+
set np =##class(isc.py.gw.DynamicObject).%New(,"np")
189
+
set arr =##class(isc.py.gw.DynamicObject).%New("np.array", "arr",,"[[1.5,2],[4,5]]")
190
+
set exp = np.exp(arr)
191
+
w $replace(exp.%GetString(),$c(10), $c(13,10))
192
+
```
193
+
194
+
And here's an example of setting property to proxy object:
195
+
196
+
```
197
+
do ##class(isc.py.init.Test).Initialize(,1)
198
+
set obj = ##class(isc.py.gw.DynamicObject).%New("Person", "p1", , "'Ed'", "25", "'Test'")
199
+
set obj2 = ##class(isc.py.gw.DynamicObject).%New("Person", "p2", , "'Bob'", "22", "'Test2'")
200
+
w obj.%GetJSON()
201
+
202
+
s obj.relative = obj2
203
+
s obj3 = obj.relative
204
+
w obj3.%GetJSON()
205
+
206
+
```
207
+
208
+
You can use `%EscapeOnSet` and `%EscapeOnCall` properties and `%IsPrimitive` method to affect default serialization behaviour.
0 commit comments