Page 1 of 1

include - self("script")?

Posted: 22 Apr 2015 13:37
by highend
Shouldn't show a

Code: Select all

include "_functions.inc"
text self("script");
the complete script including all functions from the "_functions.inc" file?

Re: include - self("script")?

Posted: 24 Apr 2015 14:29
by bdeshi
inline in-script functions aren't returned either. Maybe self('script') only returns the smallest indented region between two unindented lines where the self() statement resides.

Re: include - self("script")?

Posted: 27 Apr 2015 15:25
by TheQwerty
self('script') only returns the currently running script not all scripts within the current resource.

Code: Select all

"A" echo "A<crlf>" . self('script');
"B" echo "B<crlf>" . self('script');
Include isn't really a script command either, it's a pre-processor one - so before XY even begins running the script it makes a pass replacing the include statements with the referenced files' contents. In other words, you'll never see include within a script (or returned by self('script')). The same is true for UDFs, their definitions are not actually part of a script.

Here's something fun though:
ScriptBody.xyi:

Code: Select all

  echo 'goodbye'; // note the indentation!
Script:

Code: Select all

"Test"
  echo 'hello';
include 'ScriptBody.xyi'
  echo self('script');
Where this could come in a handy (though it is rather ugly) is with long HEREDOCs:
ScriptBody.xyi:

Code: Select all

  <<<HEREDOC
Hello world!

What's going on?
HEREDOC;
Script:

Code: Select all

"Test"
  echo // uses HEREDOC from include file
include 'ScriptBody.xyi'

Re: include - self("script")?

Posted: 27 Apr 2015 15:30
by Filehero
TheQwerty wrote:Include isn't really a script command either, it's a pre-processor one - so before XY even begins running the script it makes a pass replacing the include statements with the referenced files' contents.
To me that's classical inlining - without a compiler, of course.