Scripting: User-Defined Functions

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

Re: Scripting: User-Defined Functions

Post by admin »

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

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

Re: Scripting: User-Defined Functions

Post 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?
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin »

Cannot confirm. Everytime the include statement is met the file is freshly read from disk.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

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

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

Re: Scripting: User-Defined Functions

Post 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?
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 »

:?
nothing wrong here on my pc.

edit. also OK in ::fresh and "fresh vanilla" (new <xypath>, new <xydata>) .
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: Scripting: User-Defined Functions

Post 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?

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin »

Aaaahh!! Got it! Yep, :bug: . Only comes when you load a script from file! Hence did not see it first.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by SammaySarkar »

loading from a file here all the time! :eh: ::load 'tinc.xys';
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin »

I meant using User | Run Script | Load selected script file.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by SammaySarkar »

Oh... "Aaaahh!!" me too! :kidding:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Scripting: User-Defined Functions

Post 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
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

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

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

Re: Scripting: User-Defined Functions

Post by PeterH »

Thanks for the info. :cup:

Now, knowing that ::load works OK, I can continue to test :D
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 50012
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin »

Fixed version coming soon... :) :cup:
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

Post Reply