Page 1 of 1

INCLUDing User Functions in single line scripts

Posted: 18 Jul 2015 18:45
by SammaySarkar
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]

Re: INCLUDing User Functions in single line scripts

Posted: 18 Oct 2015 18:09
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

Re: INCLUDing User Functions in single line scripts

Posted: 20 Oct 2015 09:39
by SammaySarkar
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.

Re: INCLUDing User Functions in single line scripts

Posted: 20 Oct 2015 11:03
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.

Re: INCLUDing User Functions in single line scripts

Posted: 20 Oct 2015 19:23
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.