Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
eval
is used to execute the code on the fly.
The string has an eval
method and directly to call it as below.
"System.println(100);".eval();
The eval’s arguments are assigned to $$
like command line arguments as an array.
"System.println($$.sum());".eval(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // => 55
var code = 'System.println("hello, world");';
code.eval();
hello, world
var code = %{
using DateTime;
var dt = new DateTime("2020/12/24");
System.println(dt.toString());
};
code.eval();
2020/12/24 00:00:00
var code = %{
function evalFunction() {
try {
throw RuntimeException("Thrown from eval");
} catch (e) {
System.println("The message in eval");
throw;
}
}
evalFunction();
};
function mainFunction(code) {
code.eval();
}
try {
mainFunction(code);
} catch (e) {
System.println(e.type(), ": ", e.what());
e.printStackTrace();
}
The message in eval
RuntimeException: Thrown from eval
Stack Trace Information:
at function evalFunction(<eval>:4)
at <eval-block>(<eval>:10)
at function mainFunction(test.kx:13)
at <main-block>(test.kx:17)
"System.println($$.sum());".eval(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // => 55
55