This is not allowed. A default value can just be a simple value, not a more complex expression.SammaySarkar wrote:Code: Select all
$b = 'var_$b'; echo q(); function q($a = "1" . "2" , $b) { return $a . | . $b ; } //returns 1" . "2|var_$b
Code: Select all
function q($a = """1" . """2" , $b) { return $a . | . $b ; } //returns "1" . "2"|var_$b
Scripting: User-Defined Functions
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Sorry: exactly what I expected. Either one quoted string, or a (unquoted) number.admin wrote:This is not allowed. A default value can just be a simple value, not a more complex expression.
If the number is quoted: then it's a quoted string
OK: I have one question: what's about
Edit: silly - had to change Global to Perm!!!
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Would work (resolve perms) but not sure if it's good. I would certainly slow down all scripts using user functions...
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
New , I think.
If a Function (here: imbedded, not included, see below) Loads a script, and the script executes Caller('File'), it doesn't return the file of the function, but the file of the current active script.
I'd await either the file of the function, or at least the file of the script that owns the function. ( Oh, I think that's always the same?)
In the same situation when the script executes Caller('Caption') "function funcname" is returned, that's very good!
==> Just to say, if it makes a difference: the Function is called without assignment of the return value: I need the parameters, not the return.
(So it's more a Command with Parameters )
------------------------------------------------------------
To Perm in defaults: no problem, was just an idea.
If a Function (here: imbedded, not included, see below) Loads a script, and the script executes Caller('File'), it doesn't return the file of the function, but the file of the current active script.
I'd await either the file of the function, or at least the file of the script that owns the function. ( Oh, I think that's always the same?)
In the same situation when the script executes Caller('Caption') "function funcname" is returned, that's very good!
==> Just to say, if it makes a difference: the Function is called without assignment of the return value: I need the parameters, not the return.
(So it's more a Command with Parameters )
Code: Select all
'Main'
...
func($p1, $p2);
...
Function func($a, $b) {
...
Load 'script.xys'
...
}
To Perm in defaults: no problem, was just an idea.
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Did you try self()? Caller is not even documented...
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
But I want the opposite of self() i.e. the info about the caller of the executing script.admin wrote:Did you try self()? Caller is not even documented...
(If I remember right you made Caller() because I asked? So I know )
OK: it's not documented, so it's not a bug.
But it would be fine if you could make it work
Edit: tried Self('file') inside function doesn't work, too.
Seems to show the last loaded script!
Win11 Pro 223H2 Gerrman
Re: Scripting: User-Defined Functions
dereferenced variables are accepted by reference but not changed by reference.
Code: Select all
$var = '$a';
*$var = "refer";
$b = "refer";
echo '$a = ' . $a . <crlf> . '$b = '. $b ;
echo '$a was accepted: ' . r(*$var, $b);
echo '$a = ' . $a . <crlf> . '$b = '. $b ;
function r(&$e, &$f) {
$e = $e . 'red'; //$a
$f = $f . 'red'; //$b
return $e; //prove acceptance
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
This is a bit tricky. Will look at it later.PeterH wrote:But I want the opposite of self() i.e. the info about the caller of the executing script.admin wrote:Did you try self()? Caller is not even documented...
(If I remember right you made Caller() because I asked? So I know )
OK: it's not documented, so it's not a bug.
But it would be fine if you could make it work
Edit: tried Self('file') inside function doesn't work, too.
Seems to show the last loaded script!
FAQ | XY News RSS | XY Twitter
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Confirmed and fixed.SammaySarkar wrote:dereferenced variables are accepted by reference but not changed by reference.Code: Select all
$var = '$a'; *$var = "refer"; $b = "refer"; echo '$a = ' . $a . <crlf> . '$b = '. $b ; echo '$a was accepted: ' . r(*$var, $b); echo '$a = ' . $a . <crlf> . '$b = '. $b ; function r(&$e, &$f) { $e = $e . 'red'; //$a $f = $f . 'red'; //$b return $e; //prove acceptance }
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
1) What are the rules for naming namespaces?
2) Can namespace and include support single quotes, please?
3) I'm on the fence about this because it's certainly a bug but it could also be a nice feature. Given:
<xyscripts>\template.htmland <xyscripts>\Test.xysThe include should not be replaced since it is within a HEREDOC - and currently this breaks backwards compatibility.
2) Can namespace and include support single quotes, please?
3) I'm on the fence about this because it's certainly a bug but it could also be a nice feature. Given:
<xyscripts>\template.html
Code: Select all
<html><body>Hello $person!</body></html>
Code: Select all
"Test"
$person = 'World';
$html = <<<HTML
include "template.html"
HTML;
html($html);
Re: Scripting: User-Defined Functions
4) When include cannot find the specified file there is an error dialog:
I think it would be better if include was elevated to a full command similar to assert:This way we can customize the message to tell the user where to get the include file and prevent continuing.
5) Similarly, calling a non-existent UDF shows the stepping dialog with the error:No error is shown as it is assumed that the right-hand side of the '=' is a string, thus $ret is set to "Test::bad()".
6) include should really follow the same relative path resolution rules that load does:
7) In general we need some better error handling for detecting missing includes and UDFs.
Maybe that's in the form of try-catch:Or maybe it is in the form of some preemptive functions?The name should probably be better but I couldn't resist the chuckles.
Or maybe it is a special user function which gets run automatically when a file is included - similar to _Initialize - in this "init" function we can set variables which can be used to detect when the file is included.
The only option available to the user is "OK" which continues script execution.Error at include: The system cannot find the file specified.
include "Lib"
I think it would be better if include was elevated to a full command similar to assert:
Code: Select all
include file, [message], [continue=0]
5) Similarly, calling a non-existent UDF shows the stepping dialog with the error:
The default action when that dialog is shown is to continue which doesn't seem like the best option. To complicate matters, if the script is storing the return value of that UDF:'test::bad' is not a valid script command.
Code: Select all
$ret = Test::bad();
6) include should really follow the same relative path resolution rules that load does:
* And I sincerely hope the documentation is wrong as #2 should be checking <xyscripts> which may not be the same as <xydata>\Scripts.::help('idh_scripting_comref.htm#idh_sc_load'); wrote:(1) in the path of the calling script file (if any)
(2) in the Scripts subfolder of the application data path (variable <xydata>\Scripts)*
(3) in the application data path (variable <xydata>)
7) In general we need some better error handling for detecting missing includes and UDFs.
Maybe that's in the form of try-catch:
Code: Select all
try {
Test::bad();
} catch ($msg) { // on error - no dialog is shown, instead $msg is set to the error that would have been displayed.
End true, $msg;
}
Code: Select all
FunExists(functionName);
// Returns true if functionName exists.
// If functionName is just a namespace 'Test::', returns true if any functions in that namespace are present.
Or maybe it is a special user function which gets run automatically when a file is included - similar to _Initialize - in this "init" function we can set variables which can be used to detect when the file is included.
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
1) + 2)TheQwerty wrote:1) What are the rules for naming namespaces?
2) Can namespace and include support single quotes, please?
3) I'm on the fence about this because it's certainly a bug but it could also be a nice feature. Given:
<xyscripts>\template.htmland <xyscripts>\Test.xysCode: Select all
<html><body>Hello $person!</body></html>
The include should not be replaced since it is within a HEREDOC - and currently this breaks backwards compatibility.Code: Select all
"Test" $person = 'World'; $html = <<<HTML include "template.html" HTML; html($html);
Code: Select all
* Scripting: Included files and namespaces can now be double- or single- or
un-quoted.
* Scripting: The names of namespaces now must conform to the same rules as
the names of functions: Can only consist of letters (a-z, A-Z), numbers,
and underscores, and must not start with a number.
FAQ | XY News RSS | XY Twitter
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
4) not possible here in this pre-processing phase
5) see 4)
6) yes, it's <xyscripts>; and thanks: done and pasted to the change log.
7) later...
5) see 4)
6) yes, it's <xyscripts>; and thanks: done and pasted to the change log.
7) later...
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
1,2,3,6) Thanks!admin wrote:4) not possible here in this pre-processing phase
5) see 4)
6) yes, it's <xyscripts>; and thanks: done and pasted to the change log.
7) later...
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.
5) Thinking further, I suppose this is okay. It's not perfect but it's in line with pre-UDF behavior.
7) Maybe sooner for FunExists?
I suppose this can be worked around by being pragmatic about includes containing a specific function that checks this:
Code: Select all
namespace "Math"
function Included() { return true; }
function sum($a=0, $b=0) { return $a + $b; }
Code: Select all
include "Math"
"Test"
End Math::Included() != true, 'Math is not included.';
Echo Math::sum(21,21);
-
- Site Admin
- Posts: 60567
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Agreed!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.
FAQ | XY News RSS | XY Twitter