Scripting: User-Defined Functions
-
- Site Admin
- Posts: 60538
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
In those cases don't indent the include statement.
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Fair enough. Easy enough.admin wrote:In those cases don't indent the include statement.
Re: Scripting: User-Defined Functions
Thank you for the explanations, PeterH and SammaySarkar, and thank you Don for the change - much appreciated! (I must have missed the line immediately following a function has to unindented somewhere in the changelog)
To me, having the included statement at the beginning of the script gives me a peace of mind and a sense of neatness, and is quite logical too - I include things before they are used, and it also reminds me of C code, where # include is mostly (if not always) on top.
Also, good to know that only %things% and <things> are allowed as function default. I somehow noticed that because the workaroundworks. Well, I guess I could always do
To me, having the included statement at the beginning of the script gives me a peace of mind and a sense of neatness, and is quite logical too - I include things before they are used, and it also reminds me of C code, where # include is mostly (if not always) on top.
Also, good to know that only %things% and <things> are allowed as function default. I somehow noticed that because the workaround
Code: Select all
function myfunction($items = <get "SelectedItemsPathNames" "|">) {
//...various code...
}
Code: Select all
function myfunction($items) {
if ("$items" == "") {$items = get("SelectedItemsPathNames", "|");};
//...various code...
}
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Re: Scripting: User-Defined Functions
First question: why does indentation on the include stmt indent the included lines? Is there an advantage?
If the included lines contain a script, the caption/label seems not to be recognized if indented.
Second: as I understand, if the include is located inside of a script, and a function is included, it will be, from definition to closing }, "moved out of" the current script. (By the way: it's also callable from other scripts then.)
If a script is included, this is not recognized (as a function is) - it's interpreted as a new script starting at the including position - and being appended with the rest of the stmts behind the include. A bit strange...
If the included lines contain a script, the caption/label seems not to be recognized if indented.
Second: as I understand, if the include is located inside of a script, and a function is included, it will be, from definition to closing }, "moved out of" the current script. (By the way: it's also callable from other scripts then.)
If a script is included, this is not recognized (as a function is) - it's interpreted as a new script starting at the including position - and being appended with the rest of the stmts behind the include. A bit strange...
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60538
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Because it was never meant it to be like that. It's a workaround that just *happened* to work. Now it's not necessary anymore.Marco wrote:I must have missed the line immediately following a function has to unindented somewhere in the changelog)
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
...if you include a function.
Don't try if including a script: the old rule is in effect!
Don't try if including a script: the old rule is in effect!
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60538
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
This would not work without the new include indentation:
file echo.inc:
Code: Select all
"#1"
echo "#1";
"#2"
include echo.inc
Code: Select all
echo "Hi!";
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
This, with the fact that (semi-)inline functions are now allowed almost made me think this will finally work:
ed. all this business with indenation inspired this UDF: dedent().
Code: Select all
include "somefile.inc"; text 'yahoo!';
ed. all this business with indenation inspired this UDF: dedent().
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Scripting: User-Defined Functions
Shouldn't code to be included inside a script be indented - just as if you would code it where it belongs?admin wrote:This would not work without the new include indentation:
So in an include file, if you want to start a script, start left (best with a label), if you only want code, indent it. For the way I see these files I would understand this as "natural".
OK: my way to see it. And: if I write the include unindented I can use it as I expect, I think.
Win11 Pro 223H2 Gerrman
Re: Scripting: User-Defined Functions
introduce another preprocessor that enforces particular indentation on a line, else the line gets indented as include.
Such as this birdbrained examplethe caption will always be unindented when included.
Such as this birdbrained example
Code: Select all
<<0"demo"
hi;
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Scripting: User-Defined Functions
I second this.binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
Also, how can we call UDF's from outside (like AHK) as the include wouldn't work in a one liner and without the include statement, as the function definition would be unknown.
-
- Site Admin
- Posts: 60538
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
A good idea, but ... if the default.inc is large (and it will become large) it will slow down even the smallest scripts, including column scripts.binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
An organizational question?admin wrote:A good idea, but ... if the default.inc is large (and it will become large) it will slow down even the smallest scripts, including column scripts.binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
If each function of this type is pre-parsed (as is on include) when loaded, then moved to a "Preloaded Function Storage", the only thing XY must know about each function is Name and Location.
Only when any function is called, XY just must scan this list - (only) if the name is found, it will be touched. So the result is "like" a real XY-internal function.
Must think about: search order:
- pre-loaded first for high speed
- pre-loaded last, so in name conflict local function is executed
(Might be a use case for name spaces?)
Every user is responsible for the amount of pre-loaded functions.
XY-statistics (like Various Information) should show number and storage for pre-loaded.
Yes: some work to do. But as, in between the time, you treat a function "from definition to ending }" as one entity, it seems possible.
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60538
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
In every script all strings followed by "(" could be a user function and have to be tested against all loaded user functions. This can add up...PeterH wrote:Only when any function is called, XY just must scan this list ...
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Are'nt they also tested against all internal functions?admin wrote:In every script all strings followed by "(" could be a user function and have to be tested against all loaded user functions. This can add up...PeterH wrote:Only when any function is called, XY just must scan this list ...
Win11 Pro 223H2 Gerrman