Scripting: User-Defined Functions

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

Re: Scripting: User-Defined Functions

Post by admin »

Yes, but this can be optimized because they are hard-coded.

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

Re: Scripting: User-Defined Functions

Post by PeterH »

admin wrote:Yes, but this can be optimized because they are hard-coded.
I don't understand?

As described, there would be a list = a table of all pre-loaded user functions.
For each (name this one list has to be tested, if name can be found. (In scripting this would be just one GetTokenIndex().)
Aside from loading once, each function would only be touched, if it's name is found. Isn't that optimized?
If search order for this is last, it's only done when not found otherwise.
If this list is given a special Name Space, it can be addressed explicit, i.e. fast.
W7(x64) SP1 German
( +WXP SP3 )

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

Re: Scripting: User-Defined Functions

Post by admin »

Trust me.

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco »

What am I doing wrong? Since Saturday this doesn't work:

0. I load a fresh XY
1. I put this func.inc in <xyscripts> (warning: it modifies timestamps!)

Code: Select all

function leveldate($items = <get "SelectedItemsPathNames" "|">) {
 foreach ($item, "$items", "|") {
  $m = report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $c = report("{Created yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $a = report("{Accessed yyyy-mm-dd hh:nn:ss.fffffff}", $item);

  $x = (compare("$m", "$c", "d") == "1")?"$c":"$m";
  $x = (compare("$x", "$a", "d") == "1")?"$a":"$x";

  timestamp, "$x", "$item";
 };
}

function leveldateall($items = <get "SelectedItemsPathNames" "|">) {
 $y = report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", gettoken("$items",,"|"));

 foreach ($item, "$items", "|") {
  $m = report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $c = report("{Created yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $a = report("{Accessed yyyy-mm-dd hh:nn:ss.fffffff}", $item);

  $x = (compare("$m", "$c", "d") == "1")?"$c":"$m";
  $x = (compare("$x", "$a", "d") == "1")?"$a":"$x";

  $y = (compare("$x", "$y", "d") == "1")?"$y":"$x";
 };

 timestamp, "$y", "$items";
}

[/size]2. I select a couple of files
3. I paste this in Try Script

Code: Select all

include func.inc

 leveldate();
and run it.
All I get is an "Invalid date: $y" message.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

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

Re: Scripting: User-Defined Functions

Post by PeterH »

admin wrote:Trust me.
What stays me over?

(Sorry to English speakers: this was German :P )
W7(x64) SP1 German
( +WXP SP3 )

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Scripting: User-Defined Functions

Post by bdeshi »

@Marco, nothing selected?

when I tried with no selection, a long bad date a list of dates for all current list items (unseparated) like this is returned:

Code: Select all

set
COMMAND $m = report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", $item);
----
RESULT  $m = "2015-03-13 21:18:06.16406252011-12-27 08:44:20.00000002015-04-25 23:11:08.8496093"
Ed. because empty $item makes report() default to all current list items (and you did not add any separator in the template).
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco »

SammaySarkar wrote:@Marco, nothing selected?
No, I select a couple of files in the List.
Moreover, the first function gracefully does nothing if nothing is selected.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Scripting: User-Defined Functions

Post by bdeshi »

:? Well, I see everything working (or not working) as expected.

Just add a step in the function and debug away.


ed. "the first function gracefully does nothing if nothing is selected." -- Nope. It continues.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco »

Even with stepping enabled, XY jumps directly to the last line of code.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

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

Re: Scripting: User-Defined Functions

Post by TheQwerty »

I think Don broke the handling of the closing bracket when there are nested brackets.

This is enough to trigger it:

Code: Select all

function leveldate() {
  if (1) {
    echo 'hi';
  }
  echo 'bye';
}

 leveldate();
 echo 'end';
Results in 'bye' > 'hi' > 'end'.

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

Re: Scripting: User-Defined Functions

Post by admin »

Ugh. Fix in next ver.

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: Scripting: User-Defined Functions

Post by nerdweed »

I would suggest the following

The default.inc will only be loaded for one liners (if and only if, the one liner has a non native function.)

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

Re: Scripting: User-Defined Functions

Post by admin »

I plan to officially release functions and include in 15.20. The features work alright for everybody now? (Not asking for extra wishes -- those will come in phase 2.)

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

Re: Scripting: User-Defined Functions

Post by highend »

So far everything works fine (and still excited about them) :)
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Scripting: User-Defined Functions

Post by bdeshi »

Yep, works very very well. :appl: :appl:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply