Skip to content

Commit 8b7dc8c

Browse files
authored
Update Gateway.md
1 parent 07568c3 commit 8b7dc8c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Gateway.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,41 @@ kill obj
172172
set p1 = ##class(isc.py.gw.DynamicObject).%New(, "p1")
173173
```
174174

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.
209+
175210
# Proxy Gateway
176211

177212
Under development.

0 commit comments

Comments
 (0)