Skip to content

Commit 5451ecb

Browse files
committed
documentation of tw_output from the wiki
1 parent 82c5b67 commit 5451ecb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

_posts/2019-09-25-lp-printf.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "LP Printing with tw_output"
3+
category: feature
4+
author: "Justin LaPre"
5+
---
6+
7+
LP-level printing is available from the forward event handler.
8+
Models simply need to attach an output buffer to the event being processed, using the `tw_output` function.
9+
If this event is eventually committed, all attached output will be sent to standard-out.
10+
11+
## Example
12+
13+
void event_handler (state *s, tw_bf *bf, message *in_msg, tw_lp *lp) {
14+
// this output is associated with in_msg
15+
tw_output(lp, "this has printf functionality: %d %f %s\n", 1, 2.0, "three");
16+
}
17+
18+
19+
20+
Argument 1: The lp you're on (4th argument for your event handler).
21+
22+
Argument 2: Printf-style string, with specifiers (%-escaped codes).
23+
24+
A variable number of additional arguments are needed to pass data for each specifier.
25+
26+
### Notes
27+
28+
1. The `tw_output()` calls are associated with the event being processed.
29+
2. Multiple outputs can be attached to the same event.
30+
3. Output will always be in-order from an LP-perspective though the messages may be out-of-order from a global perspective. You may wish to include a timestamp for sorting.

0 commit comments

Comments
 (0)