From 8fc88c73f8cb99774727e7b96f9b85a8bf216c2c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 15 Nov 2021 20:22:56 +0100 Subject: shorten modules directory name (global-functions.d -> mod) --- mod/inspectvar | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mod/inspectvar (limited to 'mod/inspectvar') diff --git a/mod/inspectvar b/mod/inspectvar new file mode 100644 index 0000000..4e10fd6 --- /dev/null +++ b/mod/inspectvar @@ -0,0 +1,40 @@ +#!rsc by RouterOS +# RouterOS script: mod/inspectvar +# Copyright (c) 2020-2021 Christian Hesse +# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md + +:global InspectVar; + +# inspect variable +:set InspectVar do={ + :local Input $1; + :local Level (0 + [ :tonum $2 ]); + + :global InspectVar; + + :local PutIndent do={ + :local Prefix [ :tostr $1 ]; + :local Value [ :tostr $2 ]; + :local Level [ :tonum $3 ]; + + :local Indent ""; + :for I from=1 to=$Level step=1 do={ + :set Indent ($Indent . " "); + } + :put ($Indent . "-" . $Prefix . "-> " . $Value); + } + + :local TypeOf [ :typeof $Input ]; + $PutIndent "type" $TypeOf $Level; + + :if ($TypeOf = "array") do={ + :foreach Key,Value in=$Input do={ + $PutIndent "key" $Key ($Level + 1); + $InspectVar $Value ($Level + 2); + } + } else={ + :if ($TypeOf != "nothing") do={ + $PutIndent "value" $Input $Level; + } + } +} -- cgit v1.2.3-54-g00ecf