Lua-inspired scripting language with C-like syntax, implemented in C++20.
- C-like Syntax - Optional
;terminators,{}blocks, and C-style comments - Dynamic Typing - Lua-inspired type system with runtime flexibility
- First-Class Functions - Functions as values with closures and lexical scoping
- Powerful Tables - 0-indexed associative arrays (unlike Lua's 1-indexed)
- Modern VM - Register-based bytecode with incremental garbage collection
- Metatables - Customize table behavior with metamethods
- C++ API - Easy embedding with a Lua-like API
- Optimizations - Constant folding, loop optimization, tail call optimization, dead store elimination
// 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
- CMake 3.26 or later
- C++20 compiler (MSVC 2022+, GCC 11+, Clang 14+)
# Clone the repository git clone https://github.com/behl-lang/behl.git cd behl # Configure with CMake cmake -B build -DCMAKE_BUILD_TYPE=Release # Build (cross-platform) cmake --build build --config Release # Run tests (optional) cd build ctest -C Release --output-on-failure
The executable will be located in:
- Multi-config generators (MSVC, Xcode):
build/Release/behl[.exe] - Single-config generators (Make, Ninja):
build/behl
Create a file hello.behl:
print("Hello, World!") let name = "Behl" print("Welcome to " + name + "!")
Run it:
./behl hello.behl
let x = 42 // integer let pi = 3.14159 // number (float) let name = "Behl" // string let active = true // boolean let data = nil // nil const MAX_SIZE = 1000 // constant (semicolons optional)
// If/else with elseif if (x > 10) { print("Greater") } elseif (x == 10) { print("Equal") } else { print("Less") } // C-style for loops for (let i = 0; i < 10; i++) { print(i) } // While loops while (condition) { // ... }
function greet(name) { return "Hello, " + name + "!" } // Functions are first-class values let fn = greet print(fn("World"))
// Array-like let arr = {10, 20, 30} print(arr[0]) // 10 (first element) // Dictionary-like let person = { ["name"] = "Alice", ["age"] = 30 } print(person["name"]) // Iteration for (k, v in pairs(person)) { print(k + ": " + tostring(v)) }
#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; }
Link against the behl library:
target_link_libraries(your_target PRIVATE behl)
The complete documentation is available online and includes:
Language & Core:
- Getting Started - Installation and first steps
- Language Reference - Complete syntax and semantics
- Standard Library - Built-in functions and modules
C++ Integration:
- Embedding Guide - Complete C++ API documentation
- Examples - Code samples and patterns
Advanced:
- Optimizations - Compiler optimizations and performance
- Differences from Lua - For Lua developers
behl/
├── src/ # Source code
│ ├── frontend/ # Lexer, parser, semantic analysis
│ ├── backend/ # Compiler, bytecode generation
│ ├── vm/ # Virtual machine execution
│ ├── optimization/ # AST optimization passes
│ ├── api/ # Public C++ API
│ └── gc/ # Garbage collector
├── include/ # Public headers
├── tests/ # Unit tests (GoogleTest)
├── docs/ # Documentation
└── vscode-extension/ # VS Code language support
- C-like syntax: Optional
;terminators,{}blocks,//and/* */comments - 0-indexed tables: First element is at index 0, not 1
- Operators:
**for power (not^),!=for not equal (not~=) - Logical operators:
&&,||,!instead ofand,or,not - String concatenation:
+instead of.. - Type introspection:
typeof()instead oftype() - Module system:
import()instead ofrequire() - Variable declarations: Explicit
letandconstkeywords required
Run the test suite:
cd build
ctest -C Release --output-on-failureBehl is distributed under the MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit issues and pull requests.
Behl is inspired by Lua's elegant design and semantics, while bringing the familiarity of C-like syntax to scripting.