Java CI with Maven CodeQL Advanced
ngscript is a modern scripting language designed for the Java Virtual Machine (JVM) that combines JavaScript-like syntax with powerful coroutine support. It provides a familiar programming experience while leveraging the robust features of the JVM ecosystem.
- Java Development Kit (JDK)
- Maven
Clone the repository:
git clone https://github.com/wssccc/ngscript.git
Here's a simple Hello World example:
println("Hello, World!");
Variables in ngscript are explicitly declared using the var keyword.
Examples
Define a variable:
var counter;
Define a variable and initialize with a value:
var total = 1;
Inline definition:
for (var index = 0; index < 9; ++index) ...
Retrieve the string representation of an object's type.
Examples
println(typeof println); var number = 1; println(typeof number); println(typeof println);
Output a line to the console.
Evaluate a string as ngscript code.
println(eval("15+20"));
Named functions are registered in the global scope and can be called from anywhere in the program.
Examples
function calculateSum(firstValue, secondValue) { println(firstValue + "," + secondValue); }
Named functions were registered in global scope.
ngscript supports both traditional function expressions and arrow function syntax for concise lambda definitions.
Examples
(function (){ println("Hello, World!"); })();
var greetingFunction = function(){ println("Hello, World!"); };
val add = (x, y) => { x + y; }; val increment = (value) => { return value + 1; }; val sum = (x, y) => { return x + y; }; println("Calling an arrow function"); println(increment(1));
Similar to Java's import system, with automatic imports for common packages.
java.lang.* and java.util.* classes were imported by default.
The go statement enables concurrent execution of functions.
Examples
val concurrentTask = function(taskId) { println("Executing in concurrent routine " + taskId); }; go concurrentTask(123); println("Executing in main routine");
Advanced coroutine support for cooperative multitasking.
Examples
function processData(firstParam, secondParam) { println("Processing first parameter: " + firstParam); // Return 1 and switch to caller yield(1); // Resume here println("Processing second parameter: " + secondParam); } // Create coroutine var dataProcessor = new Coroutine(processData, "param1", "param2"); println("Coroutine status: " + dataProcessor.status()); // Call resume() to run println("Resume result 1: " + dataProcessor.resume()); println("Coroutine status: " + dataProcessor.status()); // Call resume() to run to the end of function processData println("Resume result 2: " + dataProcessor.resume()); println("Coroutine status: " + dataProcessor.status()); try { println("Attempting third resume:"); println(dataProcessor.resume()); } catch(error) { println("Could not resume, status: " + dataProcessor.status()); }
Comprehensive try-catch mechanism for robust error management.
Examples
try { println("About to throw an exception"); throw "Custom exception message"; } catch (error) { println(error.toString()); }
Seamless integration with Java objects and collections.
Examples
Create an ArrayList:
var numberList = new ArrayList(); numberList.add(1); numberList.add(2); println(numberList.toString()); numberList.remove(0); println(numberList.toString());
ngscript allows direct reference to Java methods, enabling seamless integration with Java libraries.
Examples
// Create a native Java ArrayList var numberList = new ArrayList(); // Add elements to the list numberList.add(1); numberList.add(2); numberList.add(3); // Reference to method of a Java object var getElement = numberList.get; // Call the reference to get the element at index 1 println(getElement(1));
Launch the Rose-Render example:
mvn exec:java -Dexec.mainClass=org.ngscript.examples.RoseRender
Run the conformance test suite to verify ngscript behavior:
mvn test -Dsurefire.failIfNoSpecifiedTests=false -Dtest=org.ngscript.NgscriptSpecTest