aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-12-09 16:13:00 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-12-09 16:25:49 +0100
commitb872615e897c1cf0a0a4c6d0ccf9dd155d86ec54 (patch)
tree1a949b103299e90225777e78071a04852e130115
parentcdcab4599a3d5fc6c2f6b8554e969eef536f0f1a (diff)
mod/inspectvar: introduce $InspectVarReturn
-rw-r--r--mod/inspectvar28
1 files changed, 20 insertions, 8 deletions
diff --git a/mod/inspectvar b/mod/inspectvar
index 4e10fd6..27a47fa 100644
--- a/mod/inspectvar
+++ b/mod/inspectvar
@@ -4,15 +4,24 @@
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
:global InspectVar;
+:global InspectVarReturn;
-# inspect variable
+# inspect variable and print on terminal
:set InspectVar do={
+ :global CharacterReplace;
+ :global InspectVarReturn;
+
+ :put [ $CharacterReplace [ $InspectVarReturn $1 ] ("\n") ("\n\r") ];
+}
+
+# inspect variable and return formatted string
+:set InspectVarReturn do={
:local Input $1;
:local Level (0 + [ :tonum $2 ]);
- :global InspectVar;
+ :global InspectVarReturn;
- :local PutIndent do={
+ :local IndentReturn do={
:local Prefix [ :tostr $1 ];
:local Value [ :tostr $2 ];
:local Level [ :tonum $3 ];
@@ -21,20 +30,23 @@
:for I from=1 to=$Level step=1 do={
:set Indent ($Indent . " ");
}
- :put ($Indent . "-" . $Prefix . "-> " . $Value);
+ :return ($Indent . "-" . $Prefix . "-> " . $Value);
}
:local TypeOf [ :typeof $Input ];
- $PutIndent "type" $TypeOf $Level;
+ :local Return [ $IndentReturn "type" $TypeOf $Level ];
:if ($TypeOf = "array") do={
:foreach Key,Value in=$Input do={
- $PutIndent "key" $Key ($Level + 1);
- $InspectVar $Value ($Level + 2);
+ :set $Return ($Return . "\n" . \
+ [ $IndentReturn "key" $Key ($Level + 1) ] . "\n" . \
+ [ $InspectVarReturn $Value ($Level + 2) ]);
}
} else={
:if ($TypeOf != "nothing") do={
- $PutIndent "value" $Input $Level;
+ :set $Return ($Return . "\n" . \
+ [ $IndentReturn "value" $Input $Level ]);
}
}
+ :return $Return;
}