eval with curly braces

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

eval with curly braces

Post by Bushmills » 05 Nov 2014 14:56

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

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: eval with curly braces

Post by Martin » 06 Nov 2014 17:54

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

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Re: eval with curly braces

Post by Bushmills » 06 Nov 2014 18:06

/me slaps forehead.
I should have thought of that ...
Thanks, Martin.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: eval with curly braces

Post by Martin » 06 Nov 2014 18:14

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.

Post Reply