MACORAONE / DEVELOPER DOCUMENTATION

greenServeFE 1.0.3 Examples

Executable .gsve examples for values, arrays, objects, functions, closures, native imports, and the VM server interface.

Hello world

A minimal .gsve program using the built-in print function.

print("Hello, greenServeFE");
Open .gsve sourceCanonical source

Arithmetic

Variables, arithmetic operators, and numeric values.

define a = 20;
define b = 6;
print(a + b);
print(a - b);
print(a * b);
print(a / b);
print(a % b);
Open .gsve sourceCanonical source

Arrays

Array indexing, assignment and for/in iteration.

define values = [10, 20, 30, 40];
print(values[0]);
values[1] = 25;
print(values);
for (value in values) {
    print(value);
}
Open .gsve sourceCanonical source

Objects

Object literals, named properties and property updates.

define user = {
    name: "Alex",
    role: "developer",
    active: true
};
print(user.name);
user.active = false;
print(user.active);
Open .gsve sourceCanonical source

Functions

Function code objects run in their own VM frames.

func add(a, b) {
    return a + b;
}
print(add(4, 5));
Open .gsve sourceCanonical source

Closures

The VM supports captured lexical environments and closures.

func make_adder(base) {
    func add(value) {
        return base + value;
    }
    return add;
}

define add10 = make_adder(10);
print(add10(5));
print(add10(20));
Open .gsve sourceCanonical source

Native module import

Requires the native gsnum shared library to be installed and discoverable.

import gsnum;
print(gsnum.sum(1, 2, 3, 4));
print(gsnum.mean([10, 20, 30]));
print(gsnum.sqrt(144));
Open .gsve sourceCanonical source

Server handler

Demonstrates the current VM server module interface.

import server;

func home(req, res) {
    res.send("Hello from greenServeFE");
}

server.get("/", home);
server.serve(".", 8080, {
    index: "index.html",
    static: true
});
Open .gsve sourceCanonical source

Arrays and iteration

Store values in an array and process each element with a loop.

define scores = [82, 95, 74, 88];
define total = 0;
for score in scores {
    total = total + score;
}
print(total);
print(len(scores));
Open version 1.0.3 sourceCanonical source

Objects and nested data

Represent structured application data with object properties.

define user = {
    name: "Ada",
    role: "developer",
    active: true
};
print(user.name);
print(user.role);
print(user.active);
Open version 1.0.3 sourceCanonical source

Conditions and validation

Use branches to choose behavior based on a value.

define temperature = 28;
if temperature >= 30 {
    print("Hot");
} else {
    print("Comfortable");
}
Open version 1.0.3 sourceCanonical source

HTTP API response

Explore the VM server interface and API-oriented route patterns. Networking support depends on the runtime build.

import server;

func health(req, res) {
    res.send("greenServeFE 1.0.3 is running");
}

server.get("/health", health);
Open version 1.0.3 sourceCanonical source

Run examples

make clean all
./greenServeFE docs/examples/01-hello.gsve
./greenServeFE --dump docs/examples/03-arithmetic.gsve
./greenServeFE --trace docs/examples/15-functions.gsve

For native imports, install the matching module and ensure GREENSERVE_MODULE_PATH points to its shared-library directory. External HTTP/database/crypto dependencies and network access may be required for those module examples.

Browse all canonical GSVE examplesBrowse source archive