From 00d617554fea6d04fa941e77d4131e2859c67a2b Mon Sep 17 00:00:00 2001 From: blayze Date: Sat, 12 Aug 2023 18:36:32 +0100 Subject: [PATCH] Adds initialisation example documentation to structs. --- structs.scad | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/structs.scad b/structs.scad index 9065eca..98f2ba6 100644 --- a/structs.scad +++ b/structs.scad @@ -36,6 +36,15 @@ // value = value to set the key to (when giving a single key and value) // --- // grow = Set to true to allow structure to grow, or false for new keys to generate an error. Default: true +// Example: Create a struct containing just one key-value pair +// some_struct = struct_set([], "answer", 42); +// // 'some_struct' now contains a single value, 42, under one key, "answer". +// Example: Create a struct containing more than one key-value pair. Note that keys and values need not be the same type. +// some_struct = struct_set([], ["answer", 42, 2, "two", "quote", "What a nice day"]); +// // 'some struct' now contains these key-value pairs: +// // answer: 42 +// // 2: two +// // quote: What a nice day function struct_set(struct, key, value, grow=true) = is_def(value) ? struct_set(struct,[key,value],grow=grow) :