Crea sito

5.2 pass arguments to an AVIL program



You can execute an AVIL program passing some arguments to it.
The max number of arguments you can pass is MAX_INPUT_ARGS_NUM as defined here.
You can pass as argument a string, a boolean or an integer.
Just remember to escape the double quotes whe passing a string as you can see in this sketch:

1 #include <avil.h>
2 
3 avil interpreter;
4 
5 void setup(void) {
6   
7   if(!interpreter.init()){
8      //something wrong during initialization...want to do something? 
9   }
10 
11   //run a program with arguments
12   interpreter.run("argsEx.av \"ciao\" 5");
13 }
14 
15 
16 void loop(void) {
17   //nothing to do here...
18 }

You can access the arguments value in the AVIL program's side like this:

This program produces this output:

1 first arg: ciao
2 second arg: 5

Note:


If you're using an input argument of an AVIL program as an input for a call you must first store it as a regular variable like this:

You can't use it directly like this: