<xyscripts> not properly resolved?

Discuss and share scripts and script files...
Post Reply
Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

<xyscripts> not properly resolved?

Post by Filehero »

Hi,

don't know wether the following is a bug (by means of unexpected behaviour) or works as designed.

The script example code

Code: Select all

  $cmd = "  load(getScriptPathFromINI());<crlf>  load(getScriptPath());"; 
  msg($cmd);
  load($cmd, , "s");
  


function getScriptPath() {    
    // straight return of the script path, <xyscripts> IS RESOLVED ******
    return "<xyscripts>\files_folders\DatestampMe.xys";
}


function getScriptPathFromINI() {
    
    /*
    [LIST]
    1=<xyscripts>\files_folders\DatestampMe.xys
    */
    // ini provided script path, <xyscripts> IS NOT RESOLVED ******
    return getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini");
}

The abnormality is that once the path of the script to run is read as a key from an ini file, the <xyscripts> variable as leading part of the path is not resolved anymore.
Shouldn't <xyscripts> be properly resolved here as well?

Code: Select all

    /*
    [LIST]
    1=<xyscripts>\files_folders\DatestampMe.xys
    */

Remedy: once <xyscripts> is absent from the path in the ini file reading from INI file works (again).

Code: Select all

    /*
    [LIST]
    1=files_folders\DatestampMe.xys
    */
:?:


Filehero

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: <xyscripts> not properly resolved?

Post by highend »

It's a string when you read it from a file, not an (internal XY) variable any more. You need to eval() that string to get the variable resolved
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: <xyscripts> not properly resolved?

Post by Filehero »

I've skipped noting that I already had tried to eval, but

Code: Select all

 1=<xyscripts>\files_folders\DatestampMe.xys
gives always an overflow error because of the backslashes, whereas

Code: Select all

 1=<xyscripts>
or

Code: Select all

<xyscripts>files_foldersDatestampMe.xys
works.

So I skip the variable (though I prefer the explicit notation over the inbuild implicit one), my generic menu builder (finally, no more menu script gallore) will work without it.

Thanks anyway. :)

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: <xyscripts> not properly resolved?

Post by admin »

Cannot repro.

Can you send me that scriptList.ini file?

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: <xyscripts> not properly resolved?

Post by PeterH »

I think the .ini is the mentioned:

Code: Select all

    [LIST]
    1=<xyscripts>\files_folders\DatestampMe.xys
(I hope without /* and */ :?: )

And highend is right: here <xy...> is just a string, and must be resolved by eval() after it has been read.
Win11 Pro 223H2 Gerrman

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: <xyscripts> not properly resolved?

Post by Filehero »

admin wrote:Can you send me that scriptList.ini file?
Yes, when back at home.

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: <xyscripts> not properly resolved?

Post by PeterH »

Addition: but eval must treat the value as a string (so i.e. \ will not be executed) :arrow:
Instead of
return getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini");
code
return eval("""getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini")""");
or
return eval(quote(getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini")));

(I hope I counted the ))) correct :roll: )

Edit:
return eval("""getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini")""");
is NOT clean as written (there's a function inside the double quotes, while I tested it with a constant). Correct it should be
return eval("""".getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini")."""");
or
return eval('"'.getkey(1, "LIST", "<xyscripts>\libs\scriptList.ini").'"');
Last edited by PeterH on 14 Nov 2016 12:09, edited 1 time in total.
Win11 Pro 223H2 Gerrman

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: <xyscripts> not properly resolved?

Post by Filehero »

PeterH wrote:And highend is right: here <xy...> is just a string, and must be resolved by eval() after it has been read.
Actually, I already wanted to reply that to highend's reply: I never use XY's <embedded vars> without quotes, so they are always strings. But eval was never needed to get them resolved by XY.

/e: @Peter, thanks. I will try at home.

Let's wait what Don finds.

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: <xyscripts> not properly resolved?

Post by admin »

OK, sorry, all needed info was there, no need to send anything.

You simply do this with your INI value if there is anything to resolve it in:

Code: Select all

$value = eval(quote($value));
As others already said, getkey() will not resolve the string it returns.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: <xyscripts> not properly resolved?

Post by TheQwerty »

FYI: Don't eval when you should set and reprocess:

Code: Select all

$s = '1\2';
  $e = eval($s);
  set $r, $s, 'r';
  echo "String: $s<crlf>Eval: $e<crlf>Set: $r";
Adding quote in eval helps but is easy to forget to do.

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: <xyscripts> not properly resolved?

Post by Filehero »

First of all, thanks guys for your help. I even was playing with quotes, but not at the very beginning of the processing chain. :D
admin wrote:

Code: Select all

$value = eval(quote($value));
As others already said, getkey() will not resolve the string it returns.
This looks quite awful. :ninja: Could you make it supporting "auto-expansion"?

Don't know, wether it breaks backwards compatibility. For whatever reason I - of course! - simply have assumed that <xyvars> get expanded somewhere if they get read with getkey(). Expanding the scope of <xyvars> into the configuration persistency method offered by XY SC would render that "problem" obsolete in an very elegant way.


Otherwise, I would add this little example/explanation as a usage note to the getkey() help.
admin wrote: You simply do this with your INI value if there is anything to resolve it in:

Code: Select all

$value = eval(quote($value));
As others already said, getkey() will not resolve the string it returns.

Cheers,
Filehero

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: <xyscripts> not properly resolved?

Post by admin »

Filehero wrote:First of all, thanks guys for your help. I even was playing with quotes, but not at the very beginning of the processing chain. :D
admin wrote:

Code: Select all

$value = eval(quote($value));
As others already said, getkey() will not resolve the string it returns.
This looks quite awful. :ninja:
Awful? It looks beautiful to me. :)

And I find it quite exotic to place XY variables into INI files. I'm not convinced I should add anything to handle this. After all you already can do it now in various ways as shown above.

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: <xyscripts> not properly resolved?

Post by PeterH »

Don was a bit faster than me, but anyway:

Sad to say: if you read data from a file you should expect it to be just data - and not to be changed in any way.
If, like here, you have a situation that *you* want to treat some text as a variable and substitute it's value (what, if the string would includ e.g. $a?) *you* have to tell the script that's it that way.
In theorie input-commands *could* have an option to do as you want - but I don't think it makes sense, and is worth it.

Don't forget: even when defining strings in a script *you* decide that variables are resolved: look for the difference between variable in single quoted strings (that's like the situation where you input something from a device) and double quotes (only here "imbedded" variables are resolved).

So as Don said: everything is fine here.
Win11 Pro 223H2 Gerrman

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: <xyscripts> not properly resolved?

Post by Filehero »

Jungs, alles ist gut, and I indeed do understand the sense of the eval-statement. :)

Thanks again.

FH

Post Reply