SWIG bindings for raylib (to Lua, and hopefully other languages)



SWIG binding for raylib

This repo generates raylib bindings to other languages (eg. Lua), by providing a raylib.i SWIG interface file.

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages (C#, Java, Lua, Python, Ruby, ...)

raylib is a simple and easy-to-use library to enjoy videogames programming.

Current Status

  • SWIG 4.0.2
  • raylib 3.7.0
    • raylib.h
    • raymath.h
    • rlgl.h
    • physac.h
    • easings.h
  • Supported languages:
    • Lua


This provided build method requires xmake and SWIG installed.

xmake update -s dev # SWIG file support currently requires dev branch of xmake. Will not need this line anymore after xmake publishes a release.
xmake config --menu # Config the project using a terminal ui. You choose a target language and other options in the menu `Project Configuration`.
xmake               # Build with saved configs.



Print raylib version in the terminal:

# Start luajit to test. You should change the path of the output library accordingly.
luajit -i -e "package.cpath=package.cpath..';./build/linux/x86_64/release/swig?_lua.so'"
> raylib = require "raylib"
> print(raylib.RAYLIB_VERSION)

Basic window in Lua:

-- Original version in C: https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c, by Ramon Santamaria (@raysan5)
local raylib = require "raylib"
local screenWidth, screenHeight = 800, 450
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
while not raylib.WindowShouldClose() do
    raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LIGHTGRAY)

Performance Notes

  • Because the module contains a large number(hundreds) of symbols binded, for some languages(Lua) a wrapper on top of the generated SWIG module has been added, providing only a small set of symbols when the module imported, and only automatically adding needed symbols on demand, thus saving searching time. See file raylib.i.
    • The original unwrapped module is still accessible in these languages. eg. raylib.swig in Lua.
  • Interops are expensive. Here are some tips to save interop counts:
    • If a simple struct instance is to be modified many times (eg. C Vector2 value calculated inside a loop):
      • It might not be a good idea to use the struct fields directly in complex calculations, because SWIG wraps the getter and setter functions to contain implicit C <-> script type conversions. Instead, if needed, copy the fields as local types, and after calculations copy back the results to the struct instance.
      • Note that in raylib many API functions accepting Vector2 as parameters also have a sibling version which accepts simple int x, int y, and this means in many situations you can just avoid alloc'ing and modifying C Vector2 instances at all.
    • You can modify the binding file to contain you own C functions to possibly prevent some interops happen, and generate bindings of them for your need.
  • examples/textures_bunnymark.lua is ready for benchmarking performance.

Pull Requests are welcomed

Would be nicer if this repo can be a collection featuring Ruby/Python/... bindings as well!


  • Huge thanks to @waruqi for presenting the awesome xmake build system which keeps all the messes away from the building process, also for giving many advices on the build script in this repo.


  • Embedded raylib/*.h are copied from raylib, see the beginning of each file and the original LICENSE from raylib repo.
  • examples/resources/ folder has its own LICENSE file inside.
  • Other part of the repo: MIT
  • Add examples

    Add examples

    Idea: Translate "example" folder of raylib from C to Lua

    • [x] core (done partially)
    • [x] shapes (done partially)
    • [x] textures (done partially)
    • [x] text (done partially)
    • [ ] models
    • [ ] audio
    • [ ] shaders
    • [ ] physics
    documentation enhancement 
    opened by Rinkaa 2
  • refine xmake build script

    refine xmake build script


    • [ ] ~~One xmake project per binding target language~~ Use is_config to limit project scope add_requires(See: https://github.com/RayquazaGX/swigraylib/commit/d6d3f1849da3a64c710ff76cfaa9e74a4df8a4d6#r57162758)
    • [ ] Remove xrepo install xxx step
    opened by Rinkaa 0
  • code cleanup: elimate all warnings

    code cleanup: elimate all warnings

    • rearrange Color defines, much cleaner now
    • use _Bool instead of int to define bool, to prevent some int return values in C be recognized as boolean values in Lua
    opened by Rinkaa 0
  • Some symbols (mainly macro functions and literals) are missing

    Some symbols (mainly macro functions and literals) are missing

    • [x] Color literals
    • [x] Macro aliases (ie. #define FormatText TextFormat)
    • [x] Typedef aliases (ie. typedef Vector4 Quaternion)
    opened by Rinkaa 0
  • More SWIG style declarations so less work for each target language

    More SWIG style declarations so less work for each target language


    • [ ] Use %typemap to glue up the return value array pointer with the out argument array length;
    • [ ] Use %extend to generate constructor functions for common structs, so we can prepare values during struct instance construction call in most script languages, eg. vec = raylib.Vector2(100,100)
    opened by Rinkaa 1
autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of `unsafe`

Raylib-CsLo Raylib-CsLo LowLevel autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of unsafe A focus on performance. No run

NotNot 51 Jul 25, 2022
RayLib extern bindings for Haxe

raylib-haxe Haxe bindings for RayLib usage haxelib git raylib-haxe https://github.com/haxeui/raylib-haxe package; import RayLib.*; import RayLib.Cam

HaxeUI 20 Jul 6, 2022
Utilities and common code for use with raylib

Utilities and shared components for use with raylib

Jeffery Myers 77 Aug 2, 2022
Integrate PhysFS with raylib, allowing to load images, audio and fonts from data archives.

raylib-physfs Integrate the virtual file system PhysicsFS with raylib, allowing to load images, audio, and fonts from data archives. Features Load the

Rob Loach 20 Jul 26, 2022
My collection of raylib code examples - For learning the C language with 2D and 3D games.

Raylib-Examples My collection of raylib examples. ( https://www.raylib.com/index.html ) For Raylib Version of 4 april 2020 ( Notepad++ windows install

Rudy Boudewijn van Etten 47 Jul 11, 2022
The Ultimate Raylib gaming library wrapper for Nim

NimraylibNow! - The Ultimate Raylib wrapper for Nim The most idiomatic and up-to-date wrapper for Raylib gaming C library. Use this library if you wan

Dmitry Matveyev 118 Aug 4, 2022
Load Aseprite files for animated sprites in raylib.

raylib-aseprite Load Aseprite .aseprite files for animated sprites in raylib. Features Load Aseprite files directly for use in raylib Draw individual

Rob Loach 25 Jul 27, 2022
A pong clone written in C++ with Raylib

How To Play Objective: first player to reach 10 points is the winner! PLAYER 1: W: up S: down PLAYER 2: ARROW UP or I: up ARROW DOWN or S: down Requir

Victor Sarkisov 1 Nov 8, 2021
Pong clone made in C++ with raylib

Raypong Pong clone made in C++ with raylib. Dependencies ...C++ and raylib lol Building To build, use these commands: mkdir build # Create a build dir

Mars 0 Feb 4, 2022
raylib Nuget package

raylib Nuget package This is a Nuget package for the popular raylib video game programming library. Resources used to create this package are as follo

Samuel Gomes 6 Aug 6, 2022
Minimalistic assertion library for raylib.

raylib-assert Minimalistic assertion library for raylib. Example #include "raylib.h" #include "raylib-assert.h" int main(void) { Assert(10 == 10)

Rob Loach 2 Jan 12, 2022
A top-down shooter made for the raylib 5K gamejam.

ANTISPELL Description A top-down shooter where you have to use your enemies' attacks to spell your spells! Features Absorb letters getting close to en

Francisco Javier Andrés Casas Barrientos 3 Apr 9, 2022
Python bindings for Wasm3, the fastest WebAssembly interpreter

pywasm3 Python bindings for Wasm3, the fastest WebAssembly interpreter Main repository: Wasm3 project Install # Latest release: pip3 install pywasm3

Wasm3 Labs 47 Aug 8, 2022
A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly 🚀

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly ??

Lingdong Huang 537 Aug 2, 2022
A Midnight Commander fork with scripting and other features.

⁝⁝⁝ ⋱הϵѻ⋱ Midnight Commander ⁝⁝⁝ Welcome to the ⋱Neo⋱-MC project! The goals of it are to: make the hidden gem – mcedit – shine and grow to be able to

null 136 Apr 23, 2021
CommonMark parsing and rendering library and program in C

cmark cmark is the C reference implementation of CommonMark, a rationalized version of Markdown syntax with a spec. (For the JavaScript reference impl

CommonMark 1.4k Aug 7, 2022
libcurses and dependencies taken from netbsd and brought into a portable shape (at least to musl or glibc)

netbsd-libcurses portable edition this is a port of netbsd's curses library for usage on Linux systems (tested and developed on sabotage linux, based

null 119 Jun 19, 2022
Sqrt OS is a simulation of an OS scheduler and memory manager using different scheduling algorithms including Highest Priority First (non-preemptive), Shortest Remaining Time Next, and Round Robin.

A CPU scheduler determines an order for the execution of its scheduled processes; it decides which process will run according to a certain data structure that keeps track of the processes in the system and their status. A process, upon creation, has one of the three states: Running, Ready, Blocked (doing I/O, using other resources than CPU or waiting on unavailable resource).

Abdallah Hemdan 18 Apr 15, 2022
The lightweight and modern Map SDK for Android and iOS

Open Mobile Maps The lightweight and modern Map SDK for Android (6.0+) and iOS (10+) openmobilemaps.io Getting started Readme Android Readme iOS Featu

Open Mobile Maps 89 Jul 6, 2022