MoonBit bindings for raylib 5.5 — a simple and easy-to-use library to enjoy videogames programming.
- Native target support (macOS, Linux, Windows, Android)
- Covers core, shapes, textures, text, models, shaders, and audio APIs
- Automatic resource management via GC finalizers for opaque types (Image, Texture, Font, Sound, Music, Model, etc.)
- 145 included examples — ports of official raylib examples organized by category
- Platform-specific linking handled automatically via prebuild script
A C compiler is required because raylib's C sources are compiled from source as part of the build.
| Platform | C Compiler |
|---|---|
| macOS | Xcode Command Line Tools (xcode-select --install) |
| Linux | GCC or Clang (e.g., apt install build-essential) |
| Windows | MSVC or MinGW-w64 (GCC) — see below |
| Android | Android NDK |
Either of the following C compilers will work:
-
MSVC — Install Visual Studio or the Build Tools for Visual Studio. Make sure to select the "Desktop development with C++" workload. The
cl.execompiler should be available in your PATH (use the "Developer Command Prompt" or "Developer PowerShell" that Visual Studio provides). -
MinGW-w64 (GCC) — Install via MSYS2:
- Install MSYS2 and open the MSYS2 UCRT64 terminal
- Run
pacman -S mingw-w64-ucrt-x86_64-gcc - Add the MinGW bin directory to your system
PATH(default:C:\msys64\ucrt64\bin) - Verify in a new terminal:
gcc --version
Add the dependency to your project:
moon add tonyfettes/raylibfn main {
@raylib.init_window(800, 450, "Hello Raylib")
@raylib.set_target_fps(60)
while not(@raylib.window_should_close()) {
@raylib.begin_drawing()
@raylib.clear_background(@raylib.raywhite)
@raylib.draw_text("Hello, MoonBit!", 190, 200, 20, @raylib.lightgray)
@raylib.end_drawing()
}
@raylib.close_window()
}Build and run:
moon run --target native main/Examples live in the examples/ directory as a separate module, organized by
category (core/, shapes/, textures/, text/, models/, shaders/,
audio/, others/):
# Build a specific example
moon -C examples build --target native core/core_basic_window/
# Run a specific example
moon -C examples run --target native core/core_basic_window/
# Run the bunnymark benchmark
moon -C examples run --target native textures/textures_bunnymark/Import tonyfettes/raylib and use the @raylib namespace:
// Window management
@raylib.init_window(width, height, title)
@raylib.close_window()
@raylib.set_target_fps(60)
// Drawing
@raylib.begin_drawing()
@raylib.end_drawing()
@raylib.clear_background(@raylib.skyblue)
// Shapes
@raylib.draw_rectangle(x, y, width, height, @raylib.red)
@raylib.draw_circle(x, y, radius, @raylib.blue)
// Textures
let texture = @raylib.load_texture("sprite.png")
@raylib.draw_texture(texture, x, y, @raylib.white)
// Input
@raylib.is_key_pressed(@raylib.KeySpace)
@raylib.is_mouse_button_down(@raylib.MouseButtonLeft)
@raylib.get_mouse_position() // -> Vector2
// Audio
@raylib.init_audio_device()
let sound = @raylib.load_sound("hit.wav")
@raylib.play_sound(sound)
// 3D
@raylib.begin_mode_3d(camera)
@raylib.draw_cube(position, width, height, length, @raylib.red)
@raylib.end_mode_3d()MIT