Velo by Example: Native Classes

Native classes bridge Velo to Java/Kotlin classes via reflection, enabling JVM interop.

Declare a native class with native class and native func for methods backed by JVM.

native class Terminal() {
    native func print(str text) void;
    native func input() str;

    func println(str text) void {
        print(text.con("\n"));
    };
};

Terminal term = new Terminal();
term.println("Hello!");

Register native classes in Kotlin using VeloRuntime.

// Kotlin
val runtime = VeloRuntime()
    .register(MyClass::class)
    .register("VeloName", JvmClass::class)

runtime.runFile("script.vel")

Type mapping between Velo and JVM is automatic for primitives and collections.

# Velo     → JVM
# int      → Int
# float    → Float
# str      → String
# bool     → Boolean
# byte     → Byte
# array[T] → Array<T>
# dict[K:V]→ Map<K, V>