self(file)

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Stef123

self(file)

Post 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?

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: self(file)

Post by bdeshi »

More details...
add a "step;" before the open cmd. What do you see?
How is the script called?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: self(file)

Post 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)";
To see the attached files, you need to log into the forum.

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: self(file)

Post 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.

Stef123

Re: self(file)

Post 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.

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: self(file)

Post 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.
Last edited by klownboy on 30 Apr 2015 14:39, edited 2 times in total.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: self(file)

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: self(file)

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: self(file)

Post by bdeshi »

right.

edited ^post^ with "proof" btw. :wink:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: self(file)

Post 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

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: self(file)

Post 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.

Stef123

Re: self(file)

Post 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:

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: self(file)

Post 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.
To see the attached files, you need to log into the forum.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: self(file)

Post 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.

Post Reply