Can someone explain why this isn't working?
Code: Select all
[admin@MikroTik] > local string "true";local boolean [:tobool $string];put [typeof $boolean]
nil
[admin@MikroTik] > local string "true";local boolean [:tobool $string];put [typeof $boolean]
nil
local string true;
local string "true";local boolean (string="true");put [typeof $boolean];put [$boolean]
:tobool
Actually ran into this... I thought it did work, but :tobool is just extremely conservative in what it converts. I did think it dealt with -1 as "false" – that isn't true, it's true. Very confusing difficult bug in one of my script... Anyway, why I write here so it's a little more clear how this works to me – my help to others.Currently :tobool does not work at all. If you could list all values that you would like to convert then we can try to implement it.
booltest=true using -1
booltest=false using 0
booltest=true using 1
booltest= using "1" and returns typeof nil
booltest=true using [tonum "1"] and returns typeof bool
:global booltest [:tobool -1]
:put "booltest=$booltest using -1"
:global booltest [:tobool 0]
:put "booltest=$booltest using 0"
:global booltest [:tobool 1]
:put "booltest=$booltest using 1"
:global booltest [:tobool "1"]
:put "booltest=$booltest using \"1\" and returns typeof $([:typeof $booltest])"
:global booltest [:tobool [:tonum "1"]]
:put "booltest=$booltest using [tonum \"1\"] and returns typeof $([:typeof $booltest])"