Page 1 of 1

self(file)

Posted: 30 Apr 2015 11:53
by Stef123
My PFA assigns an editor as default action for .xys
So I figured if I include this generic line in my menu-script

Code: Select all

"Edit|:udc" open self(file);
it would open the containing .xys in my editor.
But it does not work. Why?

Re: self(file)

Posted: 30 Apr 2015 13:27
by bdeshi
More details...
add a "step;" before the open cmd. What do you see?
How is the script called?

Re: self(file)

Posted: 30 Apr 2015 13:37
by Stef123
error.jpg

Code: Select all

/* my generic entries at bottom */
  $bottom = <<<BOTT
-
"Edit|:udc" open self(file);
BOTT;
Then later in the script - as part of an IF-line - but always included for all if-lines:

Code: Select all

load "$top<crlf>$image<crlf>$bottom", ,s; end(1)
BTW, it works if I define it like this:

Code: Select all

"Edit|:udc" open "self(xyscripts>\mystuff\WhiteSpaceClick.xys)";

Re: self(file)

Posted: 30 Apr 2015 13:45
by klownboy
I've been testing the line myself in some other scripts and it works properly. Stef123 are you using it within one the heredocs contained in WhiteSpaceCtxMenu script? If so it may be the heredocs. I tried it there and self ("file") return a big nothing.

Re: self(file)

Posted: 30 Apr 2015 13:49
by Stef123
klownboy wrote:Stef123 are you using it within one the heredocs contained in WhiteSpaceCtxMenu script?
Yes, exactly.
So the file-part should be in quotes? Just tried with with self("file"); but that doesn't work, either.

Re: self(file)

Posted: 30 Apr 2015 14:24
by klownboy
The help file shows "file" or other info in quotes so I did, but no, that's not causing the problem. It appears the fact that it's contained in the heredoc is causing the issue since it's returning "". I'm not sure if it's a bug since heredoc is different in the way it resolves or doesn't resolve variables though this isn't a variable.
When I place $file = self(file); up front before the heredoc and then then use openwith "$file" in the command line, it works. If $file = self(file); is placed within the heredoc just before the openwith it does not work. So self ("file") does not work within the heredoc. I don't know if this is a bug or something like a bug that just came up in the last couple betas since Don is currently making changes to caller and self. Not a bug, self(file) does not obtain the full script file name since it's being run from a script via the heredoc not the script resource file.

Re: self(file)

Posted: 30 Apr 2015 14:28
by bdeshi
you're loading the script as a script resource, not as a file.

load $bottom,,s;
here the script actually doing the self() call is not loaded from the file but from $bottom variable. Which is not a file.

ed. after loading the script from $bottom, XY starts a new,uh, "session" for that script only, and this is completely in-memory.
You have proof: add a step; before the load() "$top..." cmd and before the self() cmd.
check the topmost "file" info in the stepping dialog for each step.

Re: self(file)

Posted: 30 Apr 2015 14:35
by klownboy
OK Sammay, that makes sense it's only a script not the full script resource file. As I said above, if you assign a variable to self("file") up front in the script before the heredocs, then the variable will have the full and proper script name. So that's what you should do Stef123. Thanks.

Re: self(file)

Posted: 30 Apr 2015 14:38
by bdeshi
right.

edited ^post^ with "proof" btw. :wink:

Re: self(file)

Posted: 30 Apr 2015 14:56
by Stef123
klownboy wrote:that makes sense it's only a script not the full script resource file
Over my head. What else would "file" refer to but the very file that contains this line? It's not sitting in some include function, mind you. That I could understand. Or if I had called it self("script") or self("subscript") or anything like this.

Anyway, thank you guys for filling me in, although I cannot follow the line of reasoning here.
My intention was to use this line as a snippet. Oh well, I'll just go back to specifying the filename.xys. Easier for me than to worry about the conditional mechanics.
Thank you.
Stef

Re: self(file)

Posted: 30 Apr 2015 15:11
by klownboy
Stef123 wrote: What else would "file" refer to but the very file that contains this line? It's not sitting in some include function, mind you. That I could understand. Or if I had called it self("script") or self("subscript") or anything like this.
It boils down to the fact that where you are using self(file) is in the running of the variable "$bottom" via the load command. At that point, as far as XY is concerned it's only running a internal script not a file. That's why if you use $file = self(file) at the very top of the script XY will have the proper "file" and if you use open "$file"; end(1); it will work.

Re: self(file)

Posted: 30 Apr 2015 15:38
by Stef123
Thanks for explaining, Ken,
Got it to work in another xys, even though it's also tucked away in a sub-script over there. But never mind. I think it's a compatibility issue. Self(my) running a version of brain(my) not fully compatible with script(xy). :ninja:

Re: self(file)

Posted: 30 Apr 2015 16:46
by bdeshi
scope.png
[/size]
The green outlined section is loaded from a file (script.xys), if you do self('file') there, you get a result. (Note that there are multiple subscripts included here.)

But the red outlined section is not loaded from file, but just saved in memory as a variable at runtime, and the brown section loads that $var from memory, not from the file.

When XYplorer reads the line $var = ... it stores that string in memory, and the following load statement grabs that string from memory and instructs XY to execute it as a script. As the code saved as $var is never loaded or called directly from the file, self('file') cannot return anything.

Re: self(file)

Posted: 30 Apr 2015 17:03
by Stef123
:idea: :roll: Well done. Proves several things:
- That one picture really is worth a thousand words.
- That stuff like this were great to have in help files.
- When to use self("file") and when not.

And finally, it also illustrates my incompatibility issue. You have to completely rethink the term "file" and what all too common brains associate with it.
Thanks for clarifying.