Behl Language

Lua-inspired scripting language with C-like syntax, implemented in C++20.

Get Started View on GitHub


What is Behl?

Behl combines the simplicity and flexibility of Lua’s semantics with the familiar syntax of C-style languages. It features:

  • C-like Syntax - Familiar ; terminators, {} blocks, and C-style comments
  • Dynamic Typing - Lua-inspired type system with runtime flexibility
  • First-Class Functions - Functions are values that can be passed around
  • Tables - 0-indexed associative arrays (unlike Lua’s 1-indexed)
  • Modern VM - Register-based bytecode with incremental garbage collection
  • C++ API - Easy embedding with a Lua-like API: push_integer(), call(), etc.
  • Fast Performance - Competitive with Lua in many benchmarks

Quick Example

// C-like syntax with dynamic typing
function fibonacci(n) {
    if (n <= 1) {
        return n;
    }
    return fibonacci(n - 1) + fibonacci(n - 2);
}

let result = fibonacci(10);
print(result); // 55

Getting Started

Requirements

  • CMake 3.26 or later
  • C++20 compiler (MSVC 2022+, GCC 11+, Clang 14+)

Building

# Configure
cmake -B build -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build build --config Release

# Run tests
cd build
ctest -C Release

Your First Script

Create a file hello.behl:

print("Hello, behl!");

let name = "World";
print("Hello, " + name);

Run it:

./behl hello.behl

Key Features

Familiar Syntax

If you know C, JavaScript, or Java, you already know Behl’s syntax:

// Variables with let
let x = 10;
const PI = 3.14159;

// For loops
for (let i = 0; i < 10; i++) {
    print(i);
}

// If/else
if (x > 5) {
    print("Greater");
} else {
    print("Smaller");
}

Lua Semantics

Under the hood, Behl follows Lua’s powerful model:

  • Dynamic typing with typeof() introspection
  • Tables as the primary data structure
  • Closures and lexical scoping
  • Metatables for customizing behavior
  • Garbage collection for automatic memory management

Easy Embedding

#include <behl/behl.hpp>

int main() {
    behl::State* S = behl::new_state();
    behl::load_stdlib(S);
    
    // Load and run a script
    behl::load_string(S, "return 2 + 3");
    behl::call(S, 0, 1);
    
    int result = behl::to_integer(S, -1);
    // result == 5
    
    behl::close(S);
    return 0;
}

Documentation

Guides

Tutorials and practical examples:

Language

Complete language reference:

API

Standard library and embedding:

Standard Library:

C++ Embedding:

Advanced Topics

Technical documentation and advanced usage patterns:

License

Behl is distributed under the MIT License. See LICENSE file for details.


Copyright © 2025 behl Project. Distributed under MIT License.

This site uses Just the Docs, a documentation theme for Jekyll.