From e234a2baa210df4c4376e0b378f0b2cbbf79d84b Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Tue, 23 Jul 2019 12:42:43 +0200 Subject: Adding some examples to the README --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 4644332..bd9ac7b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,39 @@ I hope you enjoy ❤ [badge-link]: https://builds.sr.ht/~spacekookie/libbowl? [issues]: https://todo.sr.ht/~spacekookie/libbowl +Exampple +-------- + +The root structure in `libbowl` is a `bowl`. It can either be a leaf +node, containing some data (`bowl_data`, which can be many types), +or be a structure node, either in `ARRAY`, `LINK` or `HASH` mode. + +Each `libbowl` function returns a status code and uses reverse-input +pointers to communicate results. A convenience `DEBUG` macro is included. + +```C +bowl *list; +int r = bowl_malloc(&list, ARRAY); +if(r) { printf("Failed to malloc!\n"); exit(2); } + +// `DEBUG` does the same thing as the above `if` +bowl *number; +DEBUG (data_malloc(&number, INTEGER, 1312)) + +// Finally append data into list +DEBUG (bowl_append(list, number)) +``` + +Generally, `data` prefixed functions are convenience wrappers around +allocating a `bowl`, setting it's type to `LEAF`, and inserting some +data into it (performing at least 2 allocation calls). + +Freeing a `bowl` structure is as easy as calling free on the top node. + +```C +// ... +DEBUG (bowl_free(list)) +``` How to build ------------ -- cgit v1.2.3