Page 9 of 10

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 13:19
by admin
Yes, but this can be optimized because they are hard-coded.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 13:36
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.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 13:54
by admin
Trust me.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 16:59
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.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:00
by PeterH
admin wrote:Trust me.
What stays me over?

(Sorry to English speakers: this was German :P )

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:23
by SammaySarkar
@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).

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:25
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.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:31
by SammaySarkar
:? 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.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:33
by Marco
Even with stepping enabled, XY jumps directly to the last line of code.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 17:50
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'.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 18:29
by admin
Ugh. Fix in next ver.

Re: Scripting: User-Defined Functions

Posted: 04 May 2015 20:52
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.)

Re: Scripting: User-Defined Functions

Posted: 08 May 2015 10:12
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.)

Re: Scripting: User-Defined Functions

Posted: 08 May 2015 10:26
by highend
So far everything works fine (and still excited about them) :)

Re: Scripting: User-Defined Functions

Posted: 08 May 2015 10:33
by SammaySarkar
Yep, works very very well. :appl: :appl: