Import

The import statement lets you use code from other VDX files. This enables code reuse and modular project organization.

Basic syntax

import "filename.vdx";

Example

Create a utils file (utils.vdx):

class Utils {
    fn add(a, b) {
        return a + b;
    }
    
    fn greet(name) {
        return "Hello, " + name;
    }
}

Import and use it in your main file:

import "utils.vdx";

class Main {
    let sum = add(5, 3);
    print(sum);           // 8
    
    let msg = greet("VDX");
    print(msg);           // Hello, VDX
}

What gets imported

  • All functions from imported classes become available globally
  • All class definitions become available for new instantiation
  • Top-level statements in imported files are not executed

Circular imports

VDX automatically prevents circular imports. If file A imports file B, and file B imports file A, the second import is silently skipped to prevent infinite loops.

File paths

Import paths are relative to the importing file. Both relative paths ("./utils.vdx") and simple filenames ("utils.vdx") work.