Strange behaviour when calling function from other function, in combination with /import

Hi,

I’ve been struggling with a complex configuratin setup script and managed to reproduce the issue with a minimal example below.

The script calls functions, and those functions call other functions. That seems to work fine in the RouterOS console:

[admin@MikroTik] > :global myFunc do={
{...    :put "enter myFunc"           
{...    :put "exit myFunc" 
{... }                    
[admin@MikroTik] > 
[admin@MikroTik] > :global myWrapperFunc do={
{...    :put "enter myWrapperFunc"           
{...    $myFunc                   
{...    :put "exit myWrapperFunc"
{... }                           
[admin@MikroTik] > 
[admin@MikroTik] > $myWrapperFunc
enter myWrapperFunc
enter myFunc
exit myFunc
exit myWrapperFunc
[admin@MikroTik] >

But when trying executing the same lines via /import, then the inner function is silently ignored:

[admin@MikroTik] > /file print detail where name="foo.rsc"
 0 name="foo.rsc" type="script" size=184 creation-time=jan/12/1970 20:49:26 contents=
     :global myFunc do={
        :put "enter myFunc"
        :put "exit myFunc"
     }
     
     :global myWrapperFunc do={
        :put "enter myWrapperFunc"
        $myFunc
        :put "exit myWrapperFunc"
     }
     
     $myWrapperFunc
     
[admin@MikroTik] > /import foo.rsc
enter myWrapperFunc
exit myWrapperFunc

Script file loaded and executed successfully
[admin@MikroTik] >

My complex setup script, organized into several .rsc files /import’ing each other, and calling functions from other functions, seems to work when the entry script is invoked via “/system reset-configuration run-after-reset=…” and in the console, but not when the entry script is invoked via /import.

I’m using RouterOS 6.24 and the model is 2011UiAS-2HnD.

Questions:

a) Why is the behaviour different between the console and the /import command?

b) How to call a function from another function, in a way that works reliably also via the /import command?

Regards,

Ulrik

This is just a blind guess, but… Maybe add a slight delay (like 1s) per function declaration?

Perhaps the parser is trying to “compile” the second function, but doing so before the first one is ready, and since it’s all syntactically valid, it ends up compiling with nothing in the inner function.

Thanks! I now tried adding /delay 10 after each function declaration, and also in the function body before the call to $myFunc, but it did not help.

Still no answer?

Is it a bug or expected behavior or RouterOS?