Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 8
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{c,h}]
indent_size = 4

[*.lua]
indent_size = 4
max_line_length = 120

[*.nix]
indent_size = 2
1 change: 1 addition & 0 deletions .envrc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
use flake
11 changes: 8 additions & 3 deletions .gitignore
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
/.direnv/

/build/

# Compiled Lua sources
luac.out

Expand DownExpand Up@@ -40,6 +44,7 @@ luac.out

# Avoid ignoring release execs
!release/win32/rlua.exe
!src/external/lua/lib/liblua53.a
!src/external/lua/lib/liblua53dll.a
!src/external/lua/lib/lua53.dll
!src/external/lua/lib/liblua55.a
!src/external/lua/lib/liblua55.so
!src/external/lua/lib-win64/liblua55.a
!src/external/lua/lib-win64/lua55.dll
32 changes: 32 additions & 0 deletions .luarc.jsonc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"runtime": {
"version": "Lua 5.5",
},
"workspace": {
"checkThirdParty": false
},
"diagnostics": {
"unusedLocalExclude": [
"_*"
],
"groupFileStatus": {
"ambiguity": "Any",
"duplicate": "Any",
"global": "Any",
"luadoc": "None",
"redefined": "Any",
"strict": "Any",
"strong": "None",
"type-check": "Any",
"unbalanced": "Any",
"unused": "Any"
}
},
"hint": {
"enable": true,
"setType": true,
"paramType": true,
"paramName": "All"
}
}
13 changes: 13 additions & 0 deletions .stylua.toml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
block_newline_gaps = "Never"
call_parentheses = "Always"
collapse_simple_statement = "Never"
column_width = 120
indent_type = "Spaces"
indent_width = 4
line_endings = "Unix"
quote_style = "AutoPreferDouble"
space_after_function_names = "Never"
syntax = "Lua54" # TODO: update to Lua55 once https://github.com/Kampfkarren/full-moon/pull/356 is merged

[sort_requires]
enabled = true
1 change: 1 addition & 0 deletions LICENSE
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ raylib-lua is licensed under an unmodified zlib/libpng license, which is an OSI-
BSD-like license that allows static linking with closed source software:

Copyright (c) 2016-2017 Ghassan Al-Mashareqa and Ramon Santamaria (@raysan5)
Copyright (c) 2026 yilisharcs

This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Expand Down
29 changes: 24 additions & 5 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
<img align="left" src="logo/raylib-lua_256x256.png" width=256>

Lua bindings for raylib, a simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
Lua 5.5 bindings for raylib v6.0, a simple and easy-to-use library to enjoy videogames programming (www.raylib.com)

raylib-lua binding is self-contained in a header-only file: [raylib-lua.h](src/raylib-lua.h). Just include that file
in your project to allow loading and execution of raylib code written in Lua. Check [code examples](examples) for reference.
As a bonus, include [\_meta.lua](src/_meta.lua) to have LSP support.

raylib-lua could be useful for prototyping, tools development, graphic applications, embedded systems and education.

<br><br>

**WARNING: Current raylib-lua binding is very outdated! It's based on raylib 1.7 and port to newer raylib versions is stopped. Consider switching to [raylib-lua-sol](https://github.com/RobLoach/raylib-lua-sol), updated to latest raylib 2.6.**
### Build and Usage

A Linux build script is provided to compile the library and the launcher:

```bash
./build.lua
```

It supports both X11 (default) and Wayland backends. For Wayland:

```bash
CFLAGS="-D_GLFW_WAYLAND" ./build.lua
```

### rLuaLauncher

A raylib-lua launcher is also provided: [rluaLauncher](tools/rLuaLauncher/rlualauncher.c). This launcher allows you to run raylib-lua
programs from command line, or just with *drag & drop* of .lua files into *rlualauncher.exe*.
programs from the command line:

```bash
./build/rlualauncher examples/core/core_basic_window.lua
```

Note that launcher can also be compiled for other platforms, just need to link with Lua library and raylib library.
Note that the launcher can also be compiled for other platforms, just link with the Lua library and raylib library.
For more details, just check comments on sources.

### rLuaParser

In an effort to automatize raylib-lua binding generation I created [rLuaParser](https://github.com/raysan5/raylib-lua/tree/master/tools/rLuaParser), unfortunately there are several side cases that are not solved yet on the parsing, specially when dealing with opaque data types. Any help or contribution is welcome!
The bindings are automatically generated using [rLuaParser](tools/rLuaParser/rluaparser.lua), which replaces the old C parser. It
parses `raylib.h` to generate the C header-only binding and Lua metadata. The current implementation
may be incomplete; any help or contribution is welcome!

# License

raylib-lua is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.

*Copyright (c) 2016-2019 Ghassan Al-Mashareqa and Ramon Santamaria ([@raysan5](https://twitter.com/raysan5))*
*Copyright (c) 2026 yilisharcs ([@yilisharcs](https://twitter.com/yilisharcs))*
205 changes: 205 additions & 0 deletions build.lua
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
#!/usr/bin/env lua

local u <close> = assert(io.popen("uname -s"), "popen failed")
local uname = u:read("*l")

-- TODO: add Windows support (MinGW or MSVC toolchain, Win32 platform libs)
if uname ~= "Linux" then
print("ERROR: this build script only supports Linux (detected: " .. tostring(uname) .. ")")
os.exit(1)
end

local CC = os.getenv("CC") or "gcc"
local AR = os.getenv("AR") or "ar"
local CFLAGS = os.getenv("CFLAGS") or ""
local LDFLAGS = os.getenv("LDFLAGS") or ""
local BUILD = os.getenv("BUILD_DIR") or "build"
local RAYLIB_SRC_PATH = os.getenv("RAYLIB_SRC_PATH") or "../raylib/src"

-- library types: STATIC or SHARED
local RAYLIB_LIBTYPE = os.getenv("RAYLIB_LIBTYPE") or "STATIC"
local LUA_LIBTYPE = os.getenv("LUA_LIBTYPE") or "STATIC"

-- backend: X11 default (alt: -D_GLFW_WAYLAND in CFLAGS)
local glfw_flag = CFLAGS:match("-D_GLFW_[%w_]+") or "-D_GLFW_X11"
local platform_libs = glfw_flag:find("WAYLAND") and "-lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon"
or "-lX11"

local common_libs = table.concat({
"-lGL", -- OpenGL
"-lm", -- math functions, used internally
"-lpthread", -- POSIX threads
"-ldl", -- dlopen/dlsym
"-lrt", -- real-time extensions
platform_libs,
}, " ")

local function exists(path)
local f <close> = io.open(path, "r")
return f ~= nil
end

local function run(cmd)
print(cmd)
local ok = os.execute(cmd)
if not ok then
os.exit(1)
end
end

os.execute("mkdir -p " .. BUILD)

-- libraylib
local raylib_lib = (RAYLIB_LIBTYPE == "SHARED") and (BUILD .. "/libraylib.so") or (BUILD .. "/libraylib.a")

-- invalidate cache on backend switch
local marker_path = BUILD .. "/.backend"
local m_in <close> = io.open(marker_path, "r")
local old_backend = m_in and m_in:read("*l") or ""

if old_backend ~= glfw_flag and exists(raylib_lib) then
print("INFO: backend changed; rebuilding raylib")
os.execute("rm " .. raylib_lib)
end

-- generate wayland protocol headers from bundled XML
if glfw_flag:find("WAYLAND") then
local wl_deps = RAYLIB_SRC_PATH .. "/external/glfw/deps/wayland"
local protocols = {
"fractional-scale-v1.xml",
"idle-inhibit-unstable-v1.xml",
"pointer-constraints-unstable-v1.xml",
"relative-pointer-unstable-v1.xml",
"viewporter.xml",
"wayland.xml",
"xdg-activation-v1.xml",
"xdg-decoration-unstable-v1.xml",
"xdg-shell.xml",
}
for _, xml in ipairs(protocols) do
local base = xml:gsub("%.xml$", "")
run(("wayland-scanner client-header %s/%s %s/%s-client-protocol.h"):format(wl_deps, xml, BUILD, base))
run(("wayland-scanner private-code %s/%s %s/%s-client-protocol-code.h"):format(wl_deps, xml, BUILD, base))
end
end

if not exists(raylib_lib) then
local raylib_sources = {
RAYLIB_SRC_PATH .. "/raudio.c",
RAYLIB_SRC_PATH .. "/rcore.c",
RAYLIB_SRC_PATH .. "/rglfw.c",
RAYLIB_SRC_PATH .. "/rmodels.c",
RAYLIB_SRC_PATH .. "/rshapes.c",
RAYLIB_SRC_PATH .. "/rtext.c",
RAYLIB_SRC_PATH .. "/rtextures.c",
}

local raylib_cflags = table.concat({
"-std=c99",
"-DPLATFORM_DESKTOP_GLFW",
"-DGRAPHICS_API_OPENGL_33",
"-D_GNU_SOURCE",
glfw_flag,
-- raylib default, good balance of speed and perf
"-O1",
"-Wall",
-- required for shared, safe for static
"-fPIC",
CFLAGS,
-- [[ INCLUDES ]]
"-I" .. RAYLIB_SRC_PATH,
"-I" .. RAYLIB_SRC_PATH .. "/external/glfw/include",
"-I" .. BUILD,
}, " ")

if RAYLIB_LIBTYPE == "SHARED" then
run(table.concat({
CC,
"-o",
raylib_lib,
"-shared",
raylib_cflags,
table.concat(raylib_sources, " "),
-- [[ LIBS ]]
common_libs,
LDFLAGS,
}, " "))
else
-- compile raylib into object files for the static lib archive
local objs = {}
for _, src in ipairs(raylib_sources) do
local obj = BUILD .. "/" .. src:match("([^/]+)%.c$") .. ".o"
run(table.concat({
CC,
"-c",
src,
"-o",
obj,
raylib_cflags,
}, " "))
table.insert(objs, obj)
end
-- generate archive
run(table.concat({
AR,
"rcs",
raylib_lib,
table.concat(objs, " "),
}, " "))
-- cleanup artifacts
run("rm " .. table.concat(objs, " "))
end

local m <close> = io.open(marker_path, "w")
if m then
m:write(glfw_flag)
end
else
print(raylib_lib .. " found; skipping (cached)")
end

-- tools/rLuaLauncher/rlualauncher.c
local lua_lib_path = "src/external/lua/lib/liblua55.a"
if LUA_LIBTYPE == "SHARED" then
lua_lib_path = "-llua55"
-- deploy .so for shared build
if exists("src/external/lua/lib/liblua55.so") then
run("cp src/external/lua/lib/liblua55.so " .. BUILD .. "/liblua55.so")
end
end

local raylib_link = (RAYLIB_LIBTYPE == "SHARED") and "-lraylib" or raylib_lib

run(table.concat({
CC,
"-o",
BUILD .. "/rlualauncher",
"-std=c99",
-- raylib default, good balance of speed and perf
"-O1",
"-Wall",
CFLAGS,
-- [[ INCLUDES ]]
"-I" .. RAYLIB_SRC_PATH,
"-Isrc",
"-Isrc/external/lua/include",
-- [[ SOURCES ]]
"tools/rLuaLauncher/rlualauncher.c",
-- prepend lib dirs to the linker path
"-L" .. BUILD,
"-Lsrc/external/lua/lib",
-- [[ LIBS ]]
raylib_link,
lua_lib_path,
common_libs,
LDFLAGS,
-- embed the executable's dir as the dll search path at runtime
"-Wl,-rpath,'$ORIGIN'",
}, " "))

print("---")
print(raylib_lib)
print(BUILD .. "/rlualauncher")
if LUA_LIBTYPE == "SHARED" then
print(BUILD .. "/liblua55.so")
end
Loading