Ghoul is a modern scripting language designed to be terse, simple, expressive, and fast.
Note: Ghoul is crafted for personal use and experimentation. While functional and feature-complete, it's not intended for production environments.
# Function definition with closures
:make_counter(start) {
:count = start;
-> :(){
count += 1;
-> count;
}
}
# Object-oriented programming
:Greeter {
init(name) {
this.name = name;
}
greet(to) {
print "Hello " ++ to ++ ", I'm " ++ this.name ++ "!";
}
}
# Usage
:counter = make_counter(10);
print counter(); # Output: 11
print counter(); # Output: 12
:bot = Greeter("Ghoul");
bot.greet("World"); # Output: Hello World, I'm Ghoul!
Ghoul builds on Linux, macOS, and Windows with automatic dependency detection:
- Linux: GCC/Clang, Make, GNU Readline, libcurl, raylib, OpenGL libraries
- macOS: Clang, Make, Homebrew (for dependencies), raylib, readline
- Windows: MSYS2 UCRT64 environment with MinGW-w64 toolchain
- Testing: Go runtime (for test suite)
# Build the interpreter
make
# Run the REPL
./ghoul
# Run a script
./ghoul your_script.ghoul
# View build configuration
make configsudo apt update
sudo apt install build-essential libreadline-dev libcurl4-openssl-dev libraylib-dev
makesudo dnf install gcc make readline-devel libcurl-devel raylib-devel
make# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install dependencies
brew install raylib readline curl
# Build (dependencies auto-detected)
makeFor a complete Windows development environment, see the detailed Windows Setup Guide.
Quick setup:
- Install MSYS2
- Run
setup-msys2.bator./setup-msys2.shin UCRT64 terminal - Build with
make
# System-wide installation (Linux/macOS)
sudo make install
# Uninstall
sudo make uninstall
# Check installation
ghoul --version # (if version flag is implemented)# Run all tests
make test
# Build with debug symbols and sanitizers
make debug
# Build optimized release
make release# Generate compile_commands.json for LSP/IDE support
make compiledbmakeormake ghoul- Build debug version (default)make release- Build optimized versionmake debug- Build with sanitizers and debug flagsmake test- Build and run test suitemake clean- Remove build artifactsmake install- Install system-wide (requires sudo)make uninstall- Remove system installationmake config- Show current build configurationmake compiledb- Generate IDE support filesmake help- Show all available targets
- Learn Ghoul - Complete language tutorial and reference
| Library | Description | Key Features |
|---|---|---|
| Math | Mathematical functions | Trigonometry, logarithms, constants |
| JSON | JSON processing | Parse and generate JSON data |
| Request | Network requests | GET/POST requests via libcurl |
| RL | Graphics & Audio | 2D/3D graphics, input handling, audio playback |
# HTTP requests
use "Request";
use "JSON";
:headers = ["User-Agent: Ghoul-Example/1.0"];
:response = Request.get("https://api.github.com/users/octocat", headers);
:user = JSON.parse(response.response);
print user["name"];
# Graphics programming
use "RL";
RL.init_window(800, 600, "My Game");
while (!RL.window_should_close()) {
RL.begin_drawing();
RL.clear_background(RL.BLACK);
RL.draw_text("Hello Ghoul!", 10, 10, 20, RL.WHITE);
RL.end_drawing();
}
RL.close_window();
Ghoul is implemented as a bytecode interpreter with robust cross-platform support:
- Scanner (
scanner.c) - Lexical analysis and tokenization - Compiler (
compiler.c) - Single-pass bytecode compilation - Virtual Machine (
vm.c) - Stack-based bytecode execution - Memory Manager (
memory.c) - Garbage collection and allocation - Object System (
object.c) - Dynamic typing and object model - Platform Layer (
main.c) - Cross-platform executable path resolution
- Standard Library (
src/native/std.c) - Core built-in functions - Math Library (
src/native/math.c) - Mathematical operations - JSON Library (
src/native/json.c) - JSON parsing via cJSON - HTTP Library (
src/native/request.c) - Network requests via libcurl - Graphics Library (
src/native/raylib.c) - Graphics and audio via raylib
- Automatic dependency detection for Homebrew on macOS
- Robust executable path resolution on Windows, macOS, and Linux
- Smart standard library location with fallback search paths
- Platform-specific optimizations and library linking
- Comprehensive error reporting with helpful installation guidance
- Edit Code: Use any text editor or IDE (run
make compiledbfor LSP support) - Build:
makefor debug,make releasefor optimized - Test:
make testruns the complete test suite - Debug:
make debugbuilds with sanitizers, usegdb ./ghoulfor debugging - Install:
sudo make installfor system-wide installation - Clean:
make cleanremoves build artifacts
CC- C compiler (default: cc, falls back to gcc/clang)CFLAGS- Additional compiler flagsLDFLAGS- Additional linker flags
# Use specific compiler
CC=clang make
# Add custom flags
CFLAGS="-march=native" make release
# View current configuration
make config"Failed to resolve file path" after installation:
- Ensure
sudo make installcompleted successfully - Standard library should be in
/usr/local/share/ghoul/std/
Missing dependencies on Ubuntu/Debian:
sudo apt install build-essential libreadline-dev libcurl4-openssl-dev libgl1-mesa-dev libx11-devHomebrew issues on macOS:
# Reinstall dependencies
brew uninstall raylib readline
brew install raylib readline
make clean && makeWindows build issues:
- Ensure you're using MSYS2 UCRT64 environment
- Run the setup script:
./setup-msys2.sh
While Ghoul is primarily a personal project, contributions are welcome:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass (
make test) - Submit a pull request
Ghoul is open source software. See the LICENSE file for details.
- Crafting Interpreters by Robert Nystrom - The foundation for Ghoul's implementation (CLox)
- raylib - Simple and powerful graphics library
- cJSON - Lightweight JSON parser
- libcurl - Versatile HTTP client library