** "looks JavaScript, brain (contents) Ruby, (stability is AC / DC)" ** Scripting language Kinx ). This time is Tips.
What do you guys do when you make an executable file? ... yes, you usually write and compile in C or C ++. I hope it's easier to make.
Kinx does not support creating a separate exe, but in the Kinx world it allows you to create a module that can be run as an exe, pretending to be a standalone command.
A little around that.
kxrepl.exe
, kxtest.exe
In fact, since the v0.13.1 release, the commands kxrepl.exe
and kxtest.exe
are included. In the Linux version, .exe
is not attached, but kxrepl
and kxtest
.
Let's run kxrepl
.
$ kxrepl
kinx[ 0]> .quit
The REPL worked, didn't it?
Next is kxtest
.
$ kxtest -v -T declaration.md
Test Cout = 11
Entry: doc/spec/statement/declaration.md
Suite: Declaration statement
Case[ 0]: Normal case ................................... successful ( 0.10s)
Case[ 1]: With initializer .............................. successful ( 0.09s)
Case[ 2]: With initializer of expression ................ successful ( 0.09s)
Case[ 3]: Multiple variable declaration ................. successful ( 0.10s)
Case[ 4]: Constant value (1) ............................ successful ( 0.07s)
Case[ 5]: Constant value (2) ............................ successful ( 0.10s)
Case[ 6]: Constant value (3) ............................ successful ( 0.07s)
Case[ 7]: Constant value (4) ............................ successful ( 0.07s)
Case[ 8]: Constant value (5) ............................ successful ( 0.09s)
Case[ 9]: Destructuring assignment (1) .................. successful ( 0.09s)
Case[10]: Destructuring assignment (2) .................. successful ( 0.07s)
<Test Result>
Total Test Cases: 11
Successful : 11
Failed : 0
Warning : 0
SpecTest worked.
Let's try another one.
$ diff -s kxrepl kxtest
Files kxrepl and kxtest are identical
** I got the message "Files are the same" **. Or rather, that's right. The two are ** exactly the same as binaries **.
--exec
optionBefore this talk, I'll write one piece of information about Kinx options. An option called --exec
. As stated in the README, this option supports two options:
--exec: repl
... REPL.--exec: specttest
... Run SpecTest.The mechanism is as follows.
--exec: xxx
, look for lib / exec / xxx.kx
or lib / exec / 3rdparty / xxx.kx
in the folder containing the Kinx executable file.So the REPL and SpecTest work by looking for the lib / exec / repl.kx
and lib / exec / spectrum.kx
files and running them, respectively. This mechanism also allows REPL and SpecTest modifications to be made without modifying the binaries.
kxrepl
By the way, the binary of kxrepl (= binary of kxtest), how is it made (though you can probably guess). The answer is this.
name
) (you can get it from ʻargv [0]`).--exec: name
.Then what about? It will automatically refer to lib / exec / name.kx
(or lib / exec / 3rdparty / name.kx
) and execute it!
So, kxrepl
will automatically execute lib / exec / kxrepl.kx
, and kxtest
will automatically execute lib / exec / kxtest.kx
.
Hmm? Did you have such a file? Yes, I added it (= there is). Let's take a look at the contents.
lib/exec/kxrepl.kx
using exec.repl;
lib/exec/kxtest.kx
using exec.spectest;
Only this. I prepared a file that just ʻusinginside and realized it. This works fine as it will find
repl.kx and
spectest.kx according to the search path of ʻusing
. So if you replace kxrepl.exe
with repl.exe
, it works as well.
So you already know.
Here's how to create the original ʻexe file. Since Kinx dll and various libraries are required for operation, you have to put the created ʻexe
in the same place as kinx.exe
, but you can do what you want with a single command. I will.
In a concrete example.
kxcat.exe
Let's create the kxcat
command as something like the cat
command. Outputs the specified files in the specified order. Let's set it to kxcat
so that the name does not overlap with the cat
command. For the time being, there is no option, only multiple files will be accepted.
lib/exec/3rdparty/kxcat.kx
$$.each {
// Ignoring the script file name.
if (_2 > 0) {
System.print(File.load(_1));
}
};
Now, let's copy kxtest.exe
and rename it. The commands are different on Windows and Linux, but what you want to do is the same.
Windows
$ copy /y kxtest.exe kxcat.exe
Linux
$ cp -f kxtest kxcat
After copying, execute the kxcat
command as it is!
$ ./kxcat README.md ChangeLog.md
<p align="right">
<img src="https://github.com/Kray-G/kinx/workflows/Unit%20Test/badge.svg?branch=master"/>
<img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat"/>
</p>
...(abridgement)
## V0.1.0 (1st Preview Release)
* Initial Release.
You're done.
If you want to run it with the installed one, Linux has the binary of the kinx
command in the following location, so in the above case, for example, put the kxcat
command in the same location. kxrepl
and kxtest
are also placed in the same place.
$ which kinx kxrepl kxtest
/usr/bin/kinx
/usr/bin/kxrepl
/usr/bin/kxtest
It's okay to write it in C and compile it to make an executable file, but you want to make an executable file that you wrote quickly in a script. However, if you include all the necessary libraries and dlls, it will be quite large, so I tried to make it a command on the assumption that Kinx itself exists.
I think this is convenient.
Also, if you can do it immediately, for example, if you can specify the position of kinx.dll with an environment variable or pass it as an option, the .exe
file itself will be good everywhere, so that much correspondence will be done in the future. I may do it (if requested). For example, run xxx.kx
in the same location as xxx.exe
. Is that more convenient? The location of dll
needs to be specified in some way.
See you next time.