include - self("script")?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
highend
Posts: 14948
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

include - self("script")?

Post 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?
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: include - self("script")?

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: include - self("script")?

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

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: include - self("script")?

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

Post Reply