INCLUDing User Functions in single line scripts

Discuss and share scripts and script files...
Post Reply
bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

INCLUDing User Functions in single line scripts

Post by bdeshi »

I found a qeird way to utilize include files in single line scripts (addressbar, alias etc)

Code: Select all

::load readfile("<xyscripts>\inc\MyFun.xyi")."<crlf> eval();",,'s'; echo MyFun('joy');
might have to edit the indent lvl of that eval().

[code]::load readfile("<xyscripts>\inc\gpc.xyi")." eval();",,'s'; echo gpc(<curpath>,'drive');[/code]


[moved to scriptexchange]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: INCLUDing User Functions in single line scripts

Post by nerdweed »

This doesn't work for me, but something else does.

I created a UDC with just a single line - an include (which happens to be #1422)

Code: Select all

::#1422;echo gpc(<curpath>,'drive');
And this works great

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

Re: INCLUDing User Functions in single line scripts

Post by bdeshi »

it would only work with include files that have an empty line at the end. Now there's another edition which enforces an empty line, see if that works.

Your UDC shortcut is interesting too.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

autocart
Posts: 1246
Joined: 26 Sep 2013 15:22

Re: INCLUDing User Functions in single line scripts

Post by autocart »

Both nice!

Sammay, I hope you don't mind if I state the obvious:
For your own include files, if you add the eval(); as the last line in each include file, you can simply write

Code: Select all

::load "inc\MyFun.xyi"; echo MyFun('joy');
Just thinking that one-liners might be written "on the fly" at times. Therefore, the less typing and thinking the better.

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: INCLUDing User Functions in single line scripts

Post by nerdweed »

Indeed, it does work after adding an empty line.

The eval() at the end of includes makes wonders. Name the file as .xys instead of inc or xyi and this would work as well. Please see that eval(); is needed at end of the file. Alternatively, give a caption somewhere (obviously out of the function definitions)

Code: Select all

::load Main;text int(56.55);
Thanks Sammay and autocart. I have an acceptable one liner now.

See Don, what we cooked whilst you were away

Edit: eval() can also be place as first line. Using eval(); is better as using only a caption pushes an Invalid Script message in the status bar.

Post Reply