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.
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");
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 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 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 offer flexibility in defining reusable types for variables and functions.
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";
}
}
Variables are defined with const
for constants and let
for mutable values.
variables.vs
const name = "John";
let age = 30;
Functions in Vext use the fn
keyword and can accept typed parameters.
functions.vs
fn greet(name<string>) {
std->output(`Hello, ${name}`);
}
Methods use the ->
operator to interact with system or class-defined functionality.
methods.vs
std->output("Hello, World!");
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}`);
}
The global ENV
object provides access to environment-specific variables.
environment.vs
const currentUser = ENV->get("USER");
std->output(currentUser); // Outputs the current user
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");
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