Page 1 of 1

eval with curly braces

Posted: 05 Nov 2014 14:56
by Bushmills
I've been hunting down a problem with one of my flows for a day, which appears to be a bug in Automagic. As I have reported bugs before which weren't reproducible, I have this time reduced the problem to a simple script as action.
The gist of the problem is:
Conditionals using curly braces for blocks of code won't be executed when executed through eval.

Flow demonstrating the problem:
http://automagic4android.com/flow.php?i ... cb1afcdf40

Re: eval with curly braces

Posted: 06 Nov 2014 17:54
by Martin
Hi,

Automagic replaces inline expressions within string literals so the string assigned to the part {global_foo=1} is replaced by 1:

Code: Select all

"global_foo=0; if (true) { global_foo=1; }"

becomes

Code: Select all

foo="global_foo=0; if (true) 1";
You can also see this by adding a condition Debug Dialog after the script is executed.
This behavior is by design. Check out section String inline expressions in the help page of action Script.
You can use single quotes to avoid that inline expressions in strings are interpreted:

Code: Select all

foo='global_foo=0; if (true) { global_foo=1; }'
eval(foo);

Regards,
Martin

Re: eval with curly braces

Posted: 06 Nov 2014 18:06
by Bushmills
/me slaps forehead.
I should have thought of that ...
Thanks, Martin.

Re: eval with curly braces

Posted: 06 Nov 2014 18:14
by Martin
No problem, this feature is hidden quite well.
Adding syntax highlighting within string literals would make this more obvious but I did not yet have the time to implement it.