Page 2 of 10

Re: Scripting: User-Defined Functions

Posted: 10 Apr 2015 21:11
by admin
Yep.

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 01:12
by PeterH
Oh - something I'd call a bug :bug: with Includes

After I have included a (.inc-) file, this will be remembered in the current state, even after termination of the "including script".
If, after finding an error, I change the file and restart the original script to include and execute the new .inc version, still the old is executed.
The only way I found in the moment: stop/restart XY. That can't be planned?? :evil:
(I "prefer" some bugs in my scripts - for debugging I have to restart XY several times :blackstorm: to load the changed .inc)

So, if loading of Includes should be optimized: at least when the last script terminates, i.e. when no more script is active, all Includes should be dropped.
(And yes: if I have a script loading a script loading a script..., and several happen to include the same file, it's enough to load it only once.)

Or did I understand something wrong?

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 10:03
by admin
Cannot confirm. Everytime the include statement is met the file is freshly read from disk.

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 11:02
by admin
PeterH wrote:One (rather old) wish (from Load) :oops: : for include it would be very fine, if it also could replace itself with the contents of a variable (instead of a file). With this you could build a kind of script-generator. (Again: name it "Macro ability".) If it's not too difficult...
Not possible. You have to find another way to build your script-generator. :)

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 12:15
by PeterH
admin wrote:Cannot confirm. Everytime the include statement is met the file is freshly read from disk.
:shock: :shock: :shock:

Tested with minimal version: always reproducible, even from Fresh;

2 files, both in xyscript folder
tinc.xys:

Code: Select all

// test refresh of a chged .inc

include "tinc.inc"

"Label"
   $r = t(0);
   Echo "r = $r";
tinc.inc:

Code: Select all

function t($a) { return $a + 1; }
- run tinc.xys :arrow: result shows 1 OK
- change tinc.inc to add 2 instead of 1
- run tinc.xys again :arrow: result shows 1 again, should be 2
- if I run it in step mode the stmt in the function still shows + 1, not + 2
- restart XY, run again :arrow: result is 2, as expected.

So what's wrong here?

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 14:12
by SammaySarkar
:?
nothing wrong here on my pc.

edit. also OK in ::fresh and "fresh vanilla" (new <xypath>, new <xydata>) .

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 15:30
by klownboy
After changing the +1 to +2 my result was the same, like PeterH's until I restarted XY. So, what would account for the different result from Sammay's?

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 15:48
by admin
Aaaahh!! Got it! Yep, :bug: . Only comes when you load a script from file! Hence did not see it first.

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 16:09
by SammaySarkar
loading from a file here all the time! :eh: ::load 'tinc.xys';

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 16:12
by admin
I meant using User | Run Script | Load selected script file.

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 16:14
by SammaySarkar
Oh... "Aaaahh!!" me too! :kidding:

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 17:18
by PeterH
Really wouldn't have thought of that :shock:

Running from Scripting/Load Selected Script File shows that problem, while ::load tinc; doesn't!

The ::load even "repairs" the situation when the load by Scripting Menu fails :mrgreen:

Glad that it wasn't a bad dream :P

Re: Scripting: User-Defined Functions

Posted: 11 Apr 2015 17:32
by admin
A bit of explanation: I always optimize for performance, not for maintenance. That's why sometimes several entry points and pathways exist for effectively identical functionality. In this case I forgot to add a line of reset code in one of them. So your updated functions were correctly read and added, but *after* the old functions (that had not been reset). Since the first function wins by the current logic, your updated functions never were used.

Re: Scripting: User-Defined Functions

Posted: 12 Apr 2015 11:35
by PeterH
Thanks for the info. :cup:

Now, knowing that ::load works OK, I can continue to test :D

Re: Scripting: User-Defined Functions

Posted: 12 Apr 2015 11:40
by admin
Fixed version coming soon... :) :cup: