From 506a4d8978594dfaa242065bf04d0e01642e4d91 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 1 Feb 2022 02:17:52 +0900 Subject: [PATCH] README: Add a usage example The readme does not explain how to use toolbox. This commit adds two short examples how to use toolbox. --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index c171fee..955dd8f 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,33 @@ source *toolbox.sh*, you can use `include()` to load the modules that ship with toolbox, or create your own ones. +## How do I use it? + +All you have to do is source *toolbox.sh* and you can start using +the `include()` function. For example, the following code is a +minimal publisher using the *ipc* module. + + . toolbox.sh + include "ipc" + + endp=$(ipc_endpoint_open) + ipc_endpoint_publish "$endp" "mytopic" "Hello world" + +And this is the corresponding subscriber. + + . toolbox.sh + include "ipc" + + endp=$(ipc_endpoint_open) + ipc_endpoint_subscribe "$endp" "mytopic" + + if msg=$(ipc_endpoint_recv "$endp"); then + data=$(ipc_msg_get_data "$msg") + + echo "Received message: $data" + fi + + ## What modules are there? Toolbox comes with a number of modules that solve common problems. -- 2.47.3