Language Reference

The Vext Scripting Language Reference.

Introduction

The Vext scripting language provides a typed and structured environment for developing applications with built-in support for classes, inheritance, environment management, and interaction with HTML and V8. This reference covers core concepts and syntax for writing efficient Vext code.

Sample Code Overview

src/index.vs
// Importing classes
import { Person, MyPerson, Employee } from "./classes/Person.vs"

const person = new Person();
const employee = new Employee();

// Using methods
person.myMethod("Adam", 12, "New York");

// MyPerson inherits methods and adds static functionality
std->output(MyPerson.hello())

// Employee example
employee.name = "John";
employee.age = 30;
employee.position = "Developer";
employee.work();
std->output(employee.getDetails());

// Environment example
const currentUser = ENV->get("USER");

if (currentUser !== EMPTY) {
  std->output("Hello, User");
} else {
  std->error("No user found");
}

// HTML module example
const element = html->get("#byId");
const elements = html->getAll(".byClass");
const newElement = html->create("div");
html->setAttr(newElement, "id", "newId");
html->addClass(newElement, "newClass");
html->removeClass(newElement, "oldClass");

Core Concepts

Types

Vext is a statically-typed language. Types are defined using the <type> notation.

types.vs
const name<string> = "John";
const age<number> = 30;
const isStudent<boolean> = true;

Classes

Classes are the building blocks for object-oriented development. Define them with the class keyword.

classes.vs
class Person {
  name<string>;
  age<number>;

  myMethod(name<string>, age<number>, city<string>) {
    std->output(`Hello ${name}! It seems you are ${age} from ${city}`);
  }

  getDetails() {
    return `Name: ${this.name}, Age: ${this.age}`;
  }
}

Inheritance

Inheritance allows a class to extend another. Use the : character to inherit from a base class.

inheritance.vs
class Employee : Person {
  position<string>;

  work() {
    std->output(`${this.name} is working as a ${this.position}`);
  }
}

Custom Types

Custom types offer flexibility in defining reusable types for variables and functions.

custom-types.vs
type Age = number;

Static Methods

Static methods belong to the class itself rather than instances of the class. Define them using the static keyword.

static.vs
class MyPerson : Person {
  static hello() {
    return "Hello, World";
  }
}

Syntax Essentials

Variables

Variables are defined with const for constants and let for mutable values.

variables.vs
const name = "John";
let age = 30;

Functions

Functions in Vext use the fn keyword and can accept typed parameters.

functions.vs
fn greet(name<string>) {
  std->output(`Hello, ${name}`);
}

Methods

Methods use the -> operator to interact with system or class-defined functionality.

methods.vs
std->output("Hello, World!");

Empty Constants

In Vext, the EMPTY constant replaces the typical null or nil values.

empty.vs
const name<string> = EMPTY;

if (name === EMPTY) {
  std->output("Name is empty");
} else {
  std->output(`Hello, ${name}`);
}

Built-in Modules

Environment

The global ENV object provides access to environment-specific variables.

environment.vs
const currentUser = ENV->get("USER");
std->output(currentUser); // Outputs the current user

HTML

The html module enables interaction with the HTML DOM for web-based projects.

html.vs
const element = html->get("#byId");
const elements = html->getAll(".byClass");
const newElement = html->create("div");
html->setAttr(newElement, "id", "newId");
html->addClass(newElement, "newClass");
html->removeClass(newElement, "oldClass");

V8

The v8 module provides access to JavaScript's V8 engine, allowing for direct execution of JavaScript code.

v8.vs
const result = v8->run("return 1 + 1");
std->output(result); // Outputs 2