Scripting: User-Defined Functions

Features wanted...
admin
Site Admin
Posts: 49476
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 04 May 2015 13:19

Yes, but this can be optimized because they are hard-coded.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by PeterH » 04 May 2015 13:36

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: 49476
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 04 May 2015 13:54

Trust me.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by Marco » 04 May 2015 16:59

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: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 04 May 2015 17:00

admin wrote:Trust me.
What stays me over?

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

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

Re: Scripting: User-Defined Functions

Post by SammaySarkar » 04 May 2015 17:23

@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: 2303
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco » 04 May 2015 17:25

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]

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

Re: Scripting: User-Defined Functions

Post by SammaySarkar » 04 May 2015 17:31

:? 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: 2303
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco » 04 May 2015 17:33

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: 4353
Joined: 03 Aug 2007 22:30

Re: Scripting: User-Defined Functions

Post by TheQwerty » 04 May 2015 17:50

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: 49476
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 04 May 2015 18:29

Ugh. Fix in next ver.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by nerdweed » 04 May 2015 20:52

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: 49476
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 08 May 2015 10:12

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.)
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by highend » 08 May 2015 10:26

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

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

Re: Scripting: User-Defined Functions

Post by SammaySarkar » 08 May 2015 10:33

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

Post Reply