Hello everybody! This is not GPT! My question is: I want to pass a parameter from one script to another. What’s easier, you say, do it through global variables. But I want to do without variables (the interest is purely academic)
In the design :execute script=“[[:parse "[:parse [/system script get $scrName source]] $Var1 $Var2"]]”
:execute is clearly redundant, it is enough [[:parse "[:parse [/system script get $scrName source]] $Var1 $Var2"]]
From my experience, it can be seen that
all parameters are passed as string parameters and after catching them, the receiver script must convert their type back, knowing it in advance.
And secondly, strings can only be transmitted in Latin. I was unable to pass string parameters in the national language (say Cyrillic).
Questions:
Is there any way to do this more gracefully? (without global variables and functions).
And is it possible to somehow pass parameters with their types (not only in string form) and pass the Cyrillic alphabet? I tried to transfer Cyrillic alphabet in HEX format like \D0\E1, etc… - it doesn’t work.
Here, Russian friends gave me the idea that I was bothering a lot and that I could pass positional parameters like $0, $1, etc. from the script to the script … with the same construction. We should try it too.
and catching them in script Receiver is just like :local Par1 $0
Да, можно передавать и именованные и позиционные, но всё равно все превращаются в тип “str”
Yes, you can pass both named and positional ones, but still everything turns into the “str” type:
Place both scripts in your repository, run the first one and see what happens in the log
In my example, the parameters $Var1, $Var2 and $Var3 “lose” their type when they are all converted to type “str”, while the parameters $Var4 and $Var5 retain their type when passed
and in it the entry [:totime $Var5]. To pass $Var5 as a “time” type, you need to explicitly specify this again for :parse, although $Var5 is already of the “time” type.
and the design for :parse
[:to$[:typeof $Var4] $Var4]
substitutes the type of the Var4 variable on the fly into the collected string.
Now I can pass parameters without losing their types. But I can’t pass the Cyrillic alphabet in string parameters. Do you have any ideas about this? I have not tried to transfer arrays.
Thank you, friends. I guessed it myself. It’s just that string parameters need additional escaping like “" hello мамочка!"” and then they are transmitted without problems !
If I’m getting it right, you are trying to build a code in which you insert the parameters as local variables and their
value as literals. There are lots of things that can go wrong there. And is not exactly parameter passing.
Let’s have the test script:
/log info "argByName:$argByName";
/log info "arg 0:$0";
/log info "arg 1:$1";
and the runtest script:
# get the script source
:local s [/system script get test source]
# make a local function from it:
:local c [:parse $s]
# run it supplying the arguments
$c argByName="Arg1" 1