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: README.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -439,3 +439,66 @@ callback.writeLine('serverLog', 'hello, server log!')
439
439
```
440
440
441
441
Note that the `writeLine` microservice can also target `stdout` in addition to `serverLog`. `callback.writeLine('stdout', ...)` will have the same effect as running `print`. The output will be discarded.
442
+
443
+
### How do I pass values back to the caller, across rule engine plugin boundaries?
444
+
445
+
This is achieved by writing a value back _(as a string)_ to the appropriate index within the `rule_args` array. The caller is required to pass one or more variables as **out** parameters.
446
+
447
+
Here's an example demonstrating how to pass a value, via the input arguments, from the PREP to the native rule engine plugin (NREP).
448
+
449
+
The following is a python function which overwrites the value of the first input argument.
450
+
```python
451
+
# file: core.py
452
+
453
+
defget_magic_number(rule_args, callback, rei):
454
+
# Notice the integer is represented as a string.
455
+
# Only strings can be passed across rule engine plugin boundaries.
456
+
#
457
+
# Take note of the index we're writing to. The index represents the
458
+
# position of the input argument. Because this rule expects one input
459
+
# argument, we use index 0. If there were more input arguments, we could
460
+
# write to those as well using the index which identifies them.
461
+
rule_args[0] ='42'
462
+
```
463
+
464
+
And here is the NREP rule which invokes the PREP rule.
465
+
```python
466
+
# file: core.re
467
+
468
+
nrep_rule()
469
+
{
470
+
# Due to how the NREP works, we must initialize the variable to a string.
471
+
# The value of the string isn't important.
472
+
*magic_number = '-1';
473
+
474
+
# Now, we invoke the Python rule in core.py. Remember, the rule takes one
475
+
# input argument. That argument maps to index 0 within the python rule.
476
+
get_magic_number(*magic_number);
477
+
478
+
# Finally, the value is written to the log file.
479
+
writeLine('serverLog', 'The magic number is [*magic_number].');
480
+
}
481
+
```
482
+
483
+
It's important that the value passed across rule engine plugin boundaries be of type string. Passing any other type will result in an error.
484
+
485
+
Upon invoking `nrep_rule`, a message very similar to the one that follows will appear in the server log file. See the **log_message** property. It should contain `[42]` instead of `[-1]`.
486
+
```js
487
+
{
488
+
"log_category":"legacy",
489
+
"log_level":"info",
490
+
"log_message":"writeLine: inString = The magic number is [42].\n",
0 commit comments