Page 5 of 10

Re: Scripting: User-Defined Functions

Posted: 14 Apr 2015 17:25
by TheQwerty
admin wrote:
TheQwerty wrote:4) Okay, but I'm not sure OK is really the best action then. If the include file cannot be found I think it's safer to end the script than proceed.
Agreed!
Sorry, but it needs a little bit of polish.

It's okay when the including resource is a script, but when it is a script file we get two dialogs:
Dialog 1: XYplorer wrote:---------------------------
XYplorer
---------------------------
Error at include: The system cannot find the path specified.



include 'Test\Libs'
---------------------------
OK
---------------------------
(Look at all those empty lines - seems to be CR CR LF CR CR LF?)

Followed by:
Dialog 2: XYplorer wrote:---------------------------
XYplorer
---------------------------
Script file '<xyscripts>\Test\Test.xys' does not contain any valid lines.
---------------------------
OK
---------------------------
The second dialog is redundant and confusing since its message is false.

That second dialog also has two forms:
1) The stepping dialog, if the script file was called via the Load SC or the equivalent Load Script File UDC.
2) An error dialog, if the script file was loaded via Scripting > Load Selected Script File.

Re: Scripting: User-Defined Functions

Posted: 14 Apr 2015 18:09
by admin
Ah yes, I probably should have tested the code. :mrgreen:

Re: Scripting: User-Defined Functions

Posted: 15 Apr 2015 21:07
by TheQwerty
Can namespace-less function calls give preference first to functions in the same namespace before checking the global namespace?

EDIT:
Actually.. thinking on it that might be problematic because it doesn't leave a way to access the global function. The second approach of using '*' might be better since it leaves both accessible.
/edit

Code: Select all

function hello() { echo 'go away'; }

namespace a
function hello() { echo 'a says hi!'; }
function test() { hello(); }

a::test();
Alternately, perhaps '*' could be used within a namespace to mean function in the same namespace?

Code: Select all

function hello() { echo 'go away'; }

namespace a
function hello() { echo 'a says hi!'; }
function test() { *::hello(); } // Note the * here!

a::test();
In both cases I'd want the result to show 'a says hi!'.

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 12:43
by admin
What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 12:51
by Filehero
admin wrote:What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?
Since in .NET this prefix is also used for static aka global calls, it makes sense to me.

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 12:54
by TheQwerty
admin wrote:What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?
That sounds alright to me.

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 15:54
by TheQwerty
:bug: XY can crash when you start using a dozen or more arguments.

Code: Select all

function Test1($_1,$_2,$_3,$_4,$_5,$_6,$_7,$_8,$_9,$_10,$_11) { echo 'Test1'; }
function Test2($_1,$_2,$_3,$_4,$_5,$_6,$_7,$_8,$_9,$_10,$_11,$_12) { echo 'Test2'; }
function Test3($_1,$_2,$_3,$_4,$_5,$_6,$_7,$_8,$_9,$_10,$_11,$_12,$_13) { echo 'Test3'; }

"Test"
  SaveSettings;

  // All OK but #3 should probably cause an error.
  Test1(1,2,3,4,5,6,7,8,9,10);
  Test1(1,2,3,4,5,6,7,8,9,10,11);
  Test1(1,2,3,4,5,6,7,8,9,10,11,12);

  // OK
  Test2(1,2,3,4,5,6,7,8,9,10,11);
  // Rarely crashes.
  Test2(1,2,3,4,5,6,7,8,9,10,11,12);
  // Always crashes.
  Test2(1,2,3,4,5,6,7,8,9,10,11,12,13);

  // Always crashes.
  Test3(1,2,3,4,5,6,7,8,9,10,11);
  Test3(1,2,3,4,5,6,7,8,9,10,11,12);
  Test3(1,2,3,4,5,6,7,8,9,10,11,12,13);
  Test3(1,2,3,4,5,6,7,8,9,10,11,12,13,14);

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 16:25
by admin
TheQwerty wrote::bug: XY can crash when you start using a dozen or more arguments.
Yes. Will be handled smoother in next beta.

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 17:25
by admin
TheQwerty wrote:
admin wrote:What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?
That sounds alright to me.
OK, but it will remain a point on the to do list. Implementing this would be a lot of work. Needs more thought.

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 17:30
by TheQwerty
admin wrote:
TheQwerty wrote:
admin wrote:What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?
That sounds alright to me.
OK, but it will remain a point on the to do list. Implementing this would be a lot of work. Needs more thought.
That's unfortunate... Guess I'll just have to be extra careful in selecting my namespace names or be ready to search & replace when I change them. ;)

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 17:38
by admin
Simply give each function its own name... :)

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 18:12
by bdeshi
admin wrote:What about using ::hello(); (nothing before ::) to mean the global function, and hello(); to mean the local function (same namespace)?
except this edge case (just to annoy you) when the script starts with :: (because it was converted from a one liner) and the very first statement is a function call:

Code: Select all

::q();
function q() {echo "a";}
:whistle:

Re: Scripting: User-Defined Functions

Posted: 16 Apr 2015 18:22
by admin
There is a way out:

Code: Select all

call ::q();
function q() {echo "a";}

Re: Scripting: User-Defined Functions

Posted: 20 Apr 2015 05:58
by bdeshi

Code: Select all

function q() { return 1; }
echo q();
happens.

Code: Select all

echo q();
function q() { return 1; }
happens.

Code: Select all

function q() { return 1; }
 echo q();
nothing happens.

Code: Select all

 echo q();
function q() { return 1; }
happens.

Re: Scripting: User-Defined Functions

Posted: 20 Apr 2015 08:18
by bdeshi
I really need include cmd to be available for one-liners. I've saved some frequent functions as an inc file, but none can be used in addressbar quickscripts because include wants to eat the whole line.

It's possible to script an alternative but nothing as simple as include "inc\xys.inc"