Compare commits

...

36 Commits

Author SHA1 Message Date
Fierelier
8172655e88 This is how you do it 2022-05-19 03:23:33 +02:00
Fierelier
4282020b02 Change LuaJIT 2.1+ (master) tree to LuaJIT 2.0 2022-05-19 03:15:34 +02:00
Fierelier
75205209df Add notice 2022-05-19 03:14:23 +02:00
TSnake41
e7b59f1537 Update binding and LuaJIT 2022-04-12 23:39:43 +02:00
TSnake41
29052e1e85 Merge branch 'saphire-raylua_r' 2022-03-20 12:55:36 +01:00
TSnake41
dba1274bc3 Add saphire build system support for raylua_r (#3) 2022-03-20 12:53:25 +01:00
Astie Teddy
1306640357
Merge pull request #3 from sneusse/no-console
Add a new executable that doesn't show the console (windows)
2022-03-20 12:44:45 +01:00
Sebastian Neusser
2b37b77a71 only use -mwindows on windows 2022-03-18 13:03:06 +01:00
Sebastian Neusser
6a8065fcdb built new executable using the windows subsystem
- use the raylua_r to build executables without the console window
2022-03-18 12:54:42 +01:00
TSnake41
6f4cc3bba7 Update binding 2022-03-12 14:06:03 +01:00
TSnake41
c008f46e82 Update binding 2022-02-15 12:45:32 +01:00
Astie Teddy
b5247f7b61 Update binding 2022-01-18 11:11:58 +01:00
TSnake41
035703b769 Fix wrong submodule for LuaJIT 2021-12-31 12:16:04 +01:00
TSnake41
2eee7452d2 Update binding 2021-12-29 13:21:32 +01:00
TSnake41
e426d561d3 Use rewritten shaders_compute_shader based on gol raylib example. 2021-11-04 21:43:06 +01:00
TSnake41
e846857ced Added EncodeDataBase64/DecodeDataBase64 that were missing. 2021-11-04 21:17:26 +01:00
TSnake41
262a663355 raylua v4.0a 2021-11-04 20:48:32 +01:00
TSnake41
95d558cb98 Fix dll issues on Windows 2021-11-04 20:43:28 +01:00
TSnake41
0eca951b26 Update embedded ressources notice.
raylib-lua was able to load file from payload since 3c68c3cfb9
2021-10-24 13:25:58 +02:00
TSnake41
707d2309b1 Improve building and conditional declarations.
raylib-lua now manages properly `if defined` declarations.
2021-10-24 13:16:32 +02:00
TSnake41
f501ca9512 Update binding
Build by default for OpenGL 4.3 (may be changed in the future)
Now consider LUA_PATH environment variable.
2021-10-17 00:00:01 +02:00
TSnake41
9fa0231089 Merge branch 'compute-shaders' into v4.0-dev 2021-10-16 23:45:35 +02:00
TSnake41
144738427f Improve gitignore 2021-10-16 23:43:21 +02:00
TSnake41
89b1ebf081 Update saphire build system, now cleaner and more efficient. 2021-10-16 23:41:39 +02:00
TSnake41
37ef1b240c Add current saphire build system and auto-completion code 2021-10-14 21:15:36 +02:00
TSnake41
3546bf9724 Add compute shader support from TSnake41/raylib 2021-10-14 21:13:34 +02:00
TSnake41
1c94c52802 Update binding 2021-10-03 13:19:17 +02:00
TSnake41
969e64725e Add FSR and custom font examples. 2021-10-02 19:14:10 +02:00
TSnake41
8815751ac9 Early work on raylib 4.0, updated all submodules 2021-10-02 19:03:57 +02:00
TSnake41
353b431aef raylua v3.7 2021-05-02 12:11:49 +02:00
TSnake41
3c68c3cfb9 Use callback API when applicable, implement MusicStream from payload.
Update proper example.
2021-05-01 22:30:32 +02:00
TSnake41
004ac65b28 Initial raylib v3.7 version. 2021-05-01 20:21:00 +02:00
TSnake41
5a8a6feee6 WIP raylib binding update 2021-04-22 19:05:57 +02:00
TSnake41
89e0058bb4 Update binding, update LuaJIT to Tarantool's fork. 2021-02-16 22:25:45 +01:00
TSnake41
7d11e0ea51 Update binding, add core_input_mouse example 2021-02-02 20:42:17 +01:00
TSnake41
88b7d0f17e Update raylib and raygui binding. 2021-01-28 23:42:11 +01:00
43 changed files with 17135 additions and 469 deletions

14
.gitignore vendored
View File

@ -1,14 +1,12 @@
*.o
wray_standalone\.exe
src/wray_api\.c
libwray\.a
*.res
*.a
raylua_e.exe
raylua_r.exe
raylua_s.exe
raylua_s
raylua_e
src/autogen/bind.c
src/autogen/boot.c
src/autogen/builder.c
libraylua.a
src/res/icon.res
libraylua.a

5
.gitmodules vendored
View File

@ -1,10 +1,11 @@
[submodule "LuaJIT"]
path = luajit
url = https://github.com/moonjit/moonjit
url = https://github.com/LuaJIT/LuaJIT
branch = v2.0
[submodule "raylib"]
path = raylib
url = https://github.com/TSnake41/raylib
url = https://github.com/raysan5/raylib
[submodule "raygui"]
path = raygui

View File

@ -1,3 +1,5 @@
**NOTE:** This is a clone of [raylib-lua from TSnake41](https://github.com/TSnake41/raylib-lua), but using LuaJIT 2.0 instead of 2.1+, to support CPUs without SSE2.
![raylib-lua logo](assets/logo.png)
[![release](https://img.shields.io/github/v/release/TSnake41/raylib-lua?style=flat-square)](https://github.com/TSnake41/raylib-lua/releases/latest)
@ -63,8 +65,8 @@ If you need to update raylib binding, there are few tasks to do :
### Loading embedded ressources
Currently, raylib-lua doesn't support loading ressources from payload using
raylib API. However, you can still arbitrarily load files from payload using
Currently, raylib-lua support loading ressources from payload using
raylib API. You can also arbitrarily load files from payload using
`raylua.loadfile` which returns a boolean indicating success and file content.
### Making structs

168
Saphirefile.lua Normal file
View File

@ -0,0 +1,168 @@
--[[
Saphire-based build system for raylib-lua
Copyright (C) 2021 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
local saphire = require "saphire"
local c = require "saphire-c"
local Future = require "saphire-future"
local los = require "los"
local cc = os.getenv "CC" or "cc"
local ar = os.getenv "AR" or "ar"
local windres = os.getenv "WINDRES" or "windres"
-- TODO: Use current lua interpreter
local lua = os.getenv "LUA"
local needs_luajit_built = not (os.getenv "LUA")
local cflags = os.getenv "CFLAGS" or "-O2 -s"
local ldflags = os.getenv "LDFLAGS" or "-O2 -s -lm"
local ldflags_r = os.getenv "LDFLAGS_R" or ""
local modules = "raymath rlgl easings gestures physac raygui"
local graphics = os.getenv "GRAPHICS" or "GRAPHICS_API_OPENGL_43"
cflags = cflags .. " -Iluajit/src -Iraygui/src -Iraylib/src".. " -D" .. graphics
local raylua_so_path = "raylua.so" -- assume unix-like by default
local so_ldflags = ldflags
if los.type() == "linux" then
ldflags = ldflags .. " -ldl -pthread"
cflags = cflags .. " -fPIC"
so_ldflags = ldflags .. " -llua5.1"
lua = lua or "luajit/src/luajit"
elseif los.type() == "win32" then
ldflags = ldflags .. " -lopengl32 -lgdi32 -lwinmm -static "
so_ldflags = ldflags .. " -llua5.1.dll"
raylua_so_path = "raylua.dll"
ldflags_r = ldflags_r .. "-mwindows"
lua = lua or "luajit\\src\\luajit"
end
local libluajit
if saphire.targets.clean then
libluajit = {
command = "make -C luajit clean",
name = "LuaJIT"
}
else
libluajit = {
command = string.format("make -C luajit amalg CC=%s BUILDMODE=static MACOSX_DEPLOYMENT_TARGET=10.13", cc),
name = "LuaJIT"
}
end
saphire.do_single(libluajit)
libluajit[1] = "luajit/src/libluajit.a"
local libraylib = Future "raylib/src/libraylib.a"
saphire.do_subdir("raylib/src", false, "build/buildRaylib.lua", libraylib)
local function lua2c(files, output, name)
if saphire.targets.clean then
return string.format("rm -f %s", output)
else
return string.format("%s tools/lua2str.lua %s %s %s", lua, output, name, table.concat(files, " "))
end
end
local function genbind(output, modules)
if saphire.targets.clean then
return string.format("rm -f %s", output)
else
return string.format("%s tools/genbind.lua src/autogen/bind.c %s", lua, modules)
end
end
local raylua_src = {
c.src("src/raylua.c", function ()
-- Generate bind.c and boot.c
if needs_luajit_built then
-- LuaJIT needs to be built
libluajit:wait()
end
saphire.do_multi({
{
command = lua2c(
{ "src/raylib.lua", "src/compat.lua", "src/raylua.lua" },
"src/autogen/boot.c",
"raylua_boot_lua"
),
name = "boot.c"
},
{
command = genbind("src/autogen/bind.c", modules),
name = "bind.c"
}
}, true)
end)
}
local raylua_obj = c.compile(raylua_src, cflags .. " -D" .. graphics, "raylua", cc)
local libraylua = c.lib("libraylua.a", raylua_obj, "raylua", ar)
local raylua_s_src = {
"src/raylua_s.c"
}
local raylua_s_objs = c.compile(raylua_s_src, cflags, "raylua_s", cc)
local raylua_e_src = {
c.src("src/raylua_builder.c", function ()
saphire.do_single(lua2c({ "src/raylua_builder.lua" }, "src/autogen/builder.c", "raylua_builder_lua"), true)
end),
"src/raylua_e.c",
"src/lib/miniz.c",
"src/raylua_self.c",
}
local raylua_e_objs = c.compile(raylua_e_src, cflags, "raylua_e", cc)
local icon
if los.type() == "win32" then
icon = c.res("src/res/icon.rc", { "src/res/icon.ico" }, "icon", windres)
end
local raylua_s = c.link("raylua_s",
saphire.merge(raylua_s_objs, { libraylua, libraylib, libluajit, icon }),
ldflags,
false,
"raylua_s",
cc
)
local raylua_e = c.link("raylua_e",
saphire.merge(raylua_e_objs, { libraylua, libraylib, libluajit, icon }),
ldflags,
false,
"raylua_e",
cc
)
local raylua_r = c.link("raylua_r",
saphire.merge(raylua_e_objs, { libraylua, libraylib, libluajit, icon }),
ldflags .. " " .. ldflags_r,
false,
"raylua_r",
cc
)
local raylua_so = c.link(raylua_so_path,
saphire.merge(raylua_obj, { libraylib }),
so_ldflags,
true,
raylua_so_path,
cc
)

101
build/buildRaylib-bak.lua Normal file
View File

@ -0,0 +1,101 @@
local saphire = require "saphire"
local cc = os.getenv "CC" or "cc"
local ar = os.getenv "AR" or "ar"
local cflags = os.getenv "CFLAGS" or "-O2 -s"
local ldflags = os.getenv "LDFLAGS" or "-O2 -s -lm"
local include_paths = "-I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw"
local los = require "los"
local consts = {
RAYLIB_VERSION = "3.7.0",
RAYLIB_API_VERSION = "370",
}
local vars = saphire.map({
{ "RAYLIB_LIBTYPE", "STATIC" },
{ "RAYLIB_BUILD_MODE", "RELEASE" },
{ "RAYLIB_LIB_NAME", "raylib" },
{ "RAYLIB_RES_FILE", "./raylib.dll.rc.data" },
{ "PLATFORM", "PLATFORM_DESKTOP" },
{ "GRAPHICS", "GRAPHICS_API_OPENGL_33" },
{ "USE_EXTERNAL_GLFW", "FALSE" },
{ "USE_WAYLAND_DISPLAY", "FALSE" }
}, function (v)
return { v[1], os.getenv(v[1]) or v[2] }
end)
for i,v in ipairs(vars) do
vars[v[1]] = v[2]
end
local function build_c(src, obj, flags)
return {
command = string.format("%s -fdiagnostics-color=always -c -o %s %s %s %s %s", cc, obj, src, flags or "", cflags, ldflags),
name = "raylib",
display = obj
}
end
local function build_a(objs, lib)
return {
command = string.format("%s rcs %s %s", ar, lib, table.concat(objs, " ")),
name = "raylib",
lib = lib
}
end
local function build_e(files, output, flags)
return {
command = string.format("%s -fdiagnostics-color=always -o %s %s %s %s", cc, output, table.concat(files, " "), flags or "", ldflags),
name = "raylib",
display = output
}
end
local function build_res(src, output)
return {
command = string.format("%s %s -O coff %s", windres, src, output),
name = "raylib"
}
end
local objects = {
-- ["obj.o"] = { src... }
{ "rcore.o", { "rcore.c", "raylib.h", "rlgl.h", "utils.h", "raymath.h", "camera.h", "rgestures.h" } },
{ "rglfw.o", { "rglfw.c", flags = os.getenv "GLFW_OSX" or "" } },
{ "rshapes.o", { "rshapes.c", "raylib.h", "rlgl.h" } },
{ "rtextures.o", { "rtextures.c", "raylib.h", "rlgl.h", "utils.h" } },
{ "rtext.o", { "rtext.c", "raylib.h", "utils.h" } },
{ "utils.o", { "utils.c", "utils.h" } },
{ "rmodels.o", { "rmodels.c", "raylib.h", "rlgl.h", "raymath.h" } },
{ "raudio.o", { "raudio.c", "raylib.h" } }
}
if saphire.targets.clean then
saphire.do_multi(
saphire.map(objects, function (obj_info)
return {
command = string.format("rm -f %s", obj_info[1])
}
end), true)
else
saphire.do_multi(
saphire.map(objects, function (obj_info)
return function()
local obj, src = unpack(obj_info)
saphire.do_recipe(src, obj, build_c(src[1], obj,
table.concat({ "-D" .. vars.PLATFORM, "-D" .. vars.GRAPHICS, include_paths, src.flags }, " ")),
true)
end
end), true)
saphire.do_single(
build_a(
saphire.map(objects, function (obj) return obj[1] end),
"libraylib.a"),
true)
end

61
build/buildRaylib.lua Normal file
View File

@ -0,0 +1,61 @@
local future = arg[1]
local saphire = require "saphire"
local c = require "saphire-c"
local cc = os.getenv "CC" or "cc"
local ar = os.getenv "AR" or "ar"
local cflags = os.getenv "CFLAGS" or "-O2 -s"
local include_paths = "-I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw"
local los = require "los"
if los.type() == "linux" then
cflags = cflags .. " -fPIC"
end
local consts = {
RAYLIB_VERSION = "4.0.0",
RAYLIB_API_VERSION = "400",
}
local vars = saphire.map({
{ "RAYLIB_LIBTYPE", "STATIC" },
{ "RAYLIB_BUILD_MODE", "RELEASE" },
{ "RAYLIB_LIB_NAME", "raylib" },
{ "RAYLIB_RES_FILE", "./raylib.dll.rc.data" },
{ "PLATFORM", "PLATFORM_DESKTOP" },
{ "GRAPHICS", "GRAPHICS_API_OPENGL_43" },
{ "USE_EXTERNAL_GLFW", "FALSE" },
{ "USE_WAYLAND_DISPLAY", "FALSE" }
}, function (v)
return { v[1], os.getenv(v[1]) or v[2] }
end)
for i,v in ipairs(vars) do
vars[v[1]] = v[2]
end
local flags = string.format("%s -D%s -D%s %s", cflags, vars.PLATFORM, vars.GRAPHICS, include_paths)
local src = {
-- ["obj.o"] = { src... }
{ "rcore.o", { "rcore.c", "raylib.h", "rlgl.h", "utils.h", "raymath.h", "rcamera.h", "rgestures.h" } },
{ "rglfw.o", { "rglfw.c", flags = os.getenv "GLFW_OSX" or "" } },
{ "rshapes.o", { "rshapes.c", "raylib.h", "rlgl.h" } },
{ "rtextures.o", { "rtextures.c", "raylib.h", "rlgl.h", "utils.h" } },
{ "rtext.o", { "rtext.c", "raylib.h", "utils.h" } },
{ "utils.o", { "utils.c", "utils.h" } },
{ "rmodels.o", { "rmodels.c", "raylib.h", "rlgl.h", "raymath.h" } },
{ "raudio.o", { "raudio.c", "raylib.h" } }
}
local objs = c.compile(src, flags, "raylib", cc)
local libraylib = c.lib("libraylib.a", objs, "raylib")
libraylib:wait()
if future then
future:resolve()
end

View File

@ -4,10 +4,8 @@ rl.InitWindow(800, 450, "raylib [core] example - basic window")
while not rl.WindowShouldClose() do
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
rl.EndDrawing()
end

View File

@ -0,0 +1,30 @@
rl.SetTraceLogLevel(rl.LOG_WARNING)
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(800, 450, "raylib [core] example - mouse input");
local ball_position = rl.new("Vector2", -100, -100)
local ball_color = rl.DARKBLUE
while not rl.WindowShouldClose() do
ball_position.x = rl.GetMouseX()
ball_position.y = rl.GetMouseY()
if rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_LEFT) then
ball_color = rl.MAROON
elseif rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_MIDDLE) then
ball_color = rl.LIME
elseif rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_RIGHT) then
ball_color = rl.DARKBLUE
end
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
rl.DrawCircleV(ball_position, 40, ball_color)
rl.DrawText("move ball with mouse and click mouse button to change color",
10, 10, 20, rl.DARKGRAY)
rl.EndDrawing()
end
rl.CloseWindow()

View File

@ -5,11 +5,13 @@ rl.InitWindow(800, 450, "raylib [shapes] example - basic shapes drawing")
rl.InitAudioDevice()
local logo = rl.LoadTexture "ressources/logo.png"
local music = rl.LoadSound "ressources/mini1111.ogg"
local music = rl.LoadMusicStream "ressources/mini1111.xm"
rl.PlaySound(music)
rl.PlayMusicStream(music)
while not rl.WindowShouldClose() do
rl.UpdateMusicStream(music)
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
@ -19,5 +21,7 @@ while not rl.WindowShouldClose() do
rl.EndDrawing()
end
rl.UnloadMusicStream(music)
rl.CloseAudioDevice()
rl.CloseWindow()

View File

@ -0,0 +1,44 @@
local width, height = 1280, 720
rl.SetConfigFlags(rl.FLAG_WINDOW_UNDECORATED)
rl.InitWindow(width, height, "raygui - portable window")
rl.SetTargetFPS(75)
local mouse_pos = rl.new("Vector2", 0, 0)
local window_pos = rl.GetWindowPosition()
local pan_offset = rl.new("Vector2", mouse_pos)
local drag_window = false
local exit_window = false
while not exit_window and not rl.WindowShouldClose() do
mouse_pos = rl.GetMousePosition()
if rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_LEFT) then
if rl.CheckCollisionPointRec(mouse_pos, rl.new("Rectangle", 0, 0, width, 20)) then
drag_window = true
pan_offset = rl.new("Vector2", mouse_pos)
end
end
if drag_window then
window_pos = window_pos + mouse_pos - pan_offset
if rl.IsMouseButtonReleased(rl.MOUSE_BUTTON_RIGHT) then
drag_window = false
end
rl.SetWindowPosition(window_pos.x, window_pos.y)
end
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
exit_window = rl.GuiWindowBox(rl.new("Rectangle", 0, 0, width, height), "PORTABLE WINDOW")
rl.DrawText(string.format("Mouse Position: [ %.0f, %.0f ]", mouse_pos.x, mouse_pos.y),
10, 40, 10, rl.DARKGRAY)
rl.EndDrawing()
end
rl.CloseWindow()

View File

@ -20,13 +20,10 @@ local menu = lynx.menu ({
})
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
--rl.SetTargetFPS(60)
rl.InitWindow(800, 450, "raylib [lua] example - lynx menu")
while not rl.WindowShouldClose() do
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
local pos = rl.GetMousePosition()
menu:input_mouse(pos.x, pos.y, 0)

View File

@ -46,7 +46,7 @@ rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(windowWidth, windowHeight, "my 32x32 game/demo")
local target = rl.LoadRenderTexture(gameScreenWidth, gameScreenHeight)
rl.SetTextureFilter(target.texture, rl.FILTER_POINT)
rl.SetTextureFilter(target.texture, rl.TEXTURE_FILTER_POINT)
rl.SetTargetFPS(60)

View File

@ -22,10 +22,10 @@ local camera = rl.new("Camera3D", {
local num_blocks = 15
while not rl.WindowShouldClose() do
local time = rl.GetTime()
local t = rl.GetTime()
local scale = (2.0 + math.sin(time)) * 0.7
local camera_time = time * 0.3
local scale = (2.0 + math.sin(t)) * 0.7
local camera_time = t * 0.3
camera.position.x = math.cos(camera_time) * 40.0
camera.position.z = math.sin(camera_time) * 40.0
@ -40,7 +40,7 @@ while not rl.WindowShouldClose() do
for y=0,num_blocks-1 do
for z=0,num_blocks-1 do
local block_scale = (x + y + z) / 30
local scatter = math.sin(block_scale * 20.0 + time * 4.0)
local scatter = math.sin(block_scale * 20.0 + t * 4.0)
local cube_pos = rl.new("Vector3",
(x - num_blocks / 2) * (scale * 3.0) + scatter,

View File

@ -20,7 +20,7 @@ circle.enabled = false
rl.SetTargetFPS(60)
while not rl.WindowShouldClose() do
rl.RunPhysicsStep()
rl.UpdatePhysics()
if needsReset then
floor = rl.CreatePhysicsBodyRectangle({ screenWidth/2, screenHeight }, 500, 100, 10)
@ -37,9 +37,9 @@ while not rl.WindowShouldClose() do
needsReset = true
end
if rl.IsMouseButtonPressed(rl.MOUSE_LEFT_BUTTON) then
if rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_LEFT) then
rl.CreatePhysicsBodyPolygon(rl.GetMousePosition(), rl.GetRandomValue(20, 80), rl.GetRandomValue(3, 8), 10);
elseif rl.IsMouseButtonPressed(rl.MOUSE_RIGHT_BUTTON) then
elseif rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_RIGHT) then
rl.CreatePhysicsBodyCircle(rl.GetMousePosition(), rl.GetRandomValue(10, 45), 10)
end

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,41 @@
#version 430
// Game of Life logic shader
#define GOL_WIDTH 768
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
layout(std430, binding = 1) readonly restrict buffer golLayout {
uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + gl_NumWorkGroups.x * y]
};
layout(std430, binding = 2) writeonly restrict buffer golLayout2 {
uint golBufferDest[]; // golBufferDest[x, y] = golBufferDest[x + gl_NumWorkGroups.x * y]
};
#define fetchGol(x, y) ((((x) < 0) || ((y) < 0) || ((x) > GOL_WIDTH) || ((y) > GOL_WIDTH)) \
? (0) \
: golBuffer[(x) + GOL_WIDTH * (y)])
#define setGol(x, y, value) golBufferDest[(x) + GOL_WIDTH*(y)] = value
void main()
{
uint neighbourCount = 0;
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
neighbourCount += fetchGol(x - 1, y - 1); // Top left
neighbourCount += fetchGol(x, y - 1); // Top middle
neighbourCount += fetchGol(x + 1, y - 1); // Top right
neighbourCount += fetchGol(x - 1, y); // Left
neighbourCount += fetchGol(x + 1, y); // Right
neighbourCount += fetchGol(x - 1, y + 1); // Bottom left
neighbourCount += fetchGol(x, y + 1); // Bottom middle
neighbourCount += fetchGol(x + 1, y + 1); // Bottom right
if (neighbourCount == 3) setGol(x, y, 1);
else if (neighbourCount == 2) setGol(x, y, fetchGol(x, y));
else setGol(x, y, 0);
}

View File

@ -0,0 +1,29 @@
#version 430
// Game of Life rendering shader
// Just renders the content of the ssbo at binding 1 to screen
#define GOL_WIDTH 768
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
// Output fragment color
out vec4 finalColor;
// Input game of life grid.
layout(std430, binding = 1) readonly buffer golLayout
{
uint golBuffer[];
};
// Output resolution
uniform vec2 resolution;
void main()
{
ivec2 coords = ivec2(fragTexCoord*resolution);
if ((golBuffer[coords.x + coords.y*uvec2(resolution).x]) == 1) finalColor = vec4(1.0);
else finalColor = vec4(0.0, 0.0, 0.0, 1.0);
}

View File

@ -0,0 +1,51 @@
#version 430
// Game of life transfert shader
#define GOL_WIDTH 768
// Game Of Life Update Command
// NOTE: matches the structure defined on main program
struct GolUpdateCmd {
uint x; // x coordinate of the gol command
uint y; // y coordinate of the gol command
uint w; // width of the filled zone
uint enabled; // whether to enable or disable zone
};
// Local compute unit size
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
// Output game of life grid buffer
layout(std430, binding = 1) buffer golBufferLayout
{
uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + GOL_WIDTH * y]
};
// Command buffer
layout(std430, binding = 3) readonly restrict buffer golUpdateLayout
{
uint count;
GolUpdateCmd commands[];
};
#define isInside(x, y) (((x) >= 0) && ((y) >= 0) && ((x) < GOL_WIDTH) && ((y) < GOL_WIDTH))
#define getBufferIndex(x, y) ((x) + GOL_WIDTH * (y))
void main()
{
uint cmdIndex = gl_GlobalInvocationID.x;
GolUpdateCmd cmd = commands[cmdIndex];
for (uint x = cmd.x; x < (cmd.x + cmd.w); x++)
{
for (uint y = cmd.y; y < (cmd.y + cmd.w); y++)
{
if (isInside(x, y))
{
if (cmd.enabled != 0) atomicOr(golBuffer[getBufferIndex(x, y)], 1);
else atomicAnd(golBuffer[getBufferIndex(x, y)], 0);
}
}
}
}

View File

@ -0,0 +1,134 @@
local ffi = require "ffi"
-- IMPORTANT: This must match gol*.glsl GOL_WIDTH constant.
-- This must be a multiple of 16 (check golLogic compute dispatch).
local GOL_WIDTH = 768
-- Maximum amount of queued draw commands (squares draw from mouse down events).
local MAX_BUFFERED_TRANSFERTS = 48
ffi.cdef [[
typedef struct GolUpdateCmd {
unsigned int x;
unsigned int y;
unsigned int w;
unsigned int enabled;
} GolUpdateCmd;
]]
ffi.cdef(string.format([[
typedef struct GolUpdateSSBO {
unsigned int count;
GolUpdateCmd commands[%d];
} GolUpdateSSBO;
]], MAX_BUFFERED_TRANSFERTS))
rl.InitWindow(GOL_WIDTH, GOL_WIDTH, "raylib [rlgl] example - compute shader - game of life")
local resolution = rl.new("Vector2", GOL_WIDTH, GOL_WIDTH)
local brushSize = 8
-- Game of Life logic compute shader
local golLogicCode = rl.LoadFileText("resources/glsl430/gol.glsl")
local golLogicShader = rl.rlCompileShader(golLogicCode, rl.RL_COMPUTE_SHADER);
local golLogicProgram = rl.rlLoadComputeShaderProgram(golLogicShader);
rl.UnloadFileText(golLogicCode);
-- Game of Life rendering compute shader
local golRenderShader = rl.LoadShader(nil, "resources/glsl430/gol_render.glsl")
local resUniformLoc = rl.GetShaderLocation(golRenderShader, "resolution")
local golTransfertCode = rl.LoadFileText("resources/glsl430/gol_transfert.glsl");
local golTransfertShader = rl.rlCompileShader(golTransfertCode, rl.RL_COMPUTE_SHADER);
local golTransfertProgram = rl.rlLoadComputeShaderProgram(golTransfertShader);
rl.UnloadFileText(golTransfertCode);
local ssboSize = ffi.sizeof("int[?]", GOL_WIDTH * GOL_WIDTH)
local ssboA = rl.rlLoadShaderBuffer(ssboSize, nil, rl.RL_DYNAMIC_COPY);
local ssboB = rl.rlLoadShaderBuffer(ssboSize, nil, rl.RL_DYNAMIC_COPY);
local transfertBuffer = ffi.new("struct GolUpdateSSBO")
transfertBuffer.count = 0
local transfertBufferSize = ffi.sizeof "struct GolUpdateSSBO"
local transfertSSBO = rl.rlLoadShaderBuffer(transfertBufferSize, nil, rl.RL_DYNAMIC_COPY);
-- Create a white texture of the size of the window to update
-- each pixel of the window using the fragment shader
local whiteImage = rl.GenImageColor(GOL_WIDTH, GOL_WIDTH, rl.WHITE);
local whiteTex = rl.LoadTextureFromImage(whiteImage);
rl.UnloadImage(whiteImage)
while not rl.WindowShouldClose() do
brushSize = math.floor(brushSize + rl.GetMouseWheelMove())
if ((rl.IsMouseButtonDown(rl.MOUSE_BUTTON_LEFT) or rl.IsMouseButtonDown(rl.MOUSE_BUTTON_RIGHT))
and (transfertBuffer.count < MAX_BUFFERED_TRANSFERTS)) then
-- Buffer a new command
transfertBuffer.commands[transfertBuffer.count].x = rl.GetMouseX() - brushSize/2
transfertBuffer.commands[transfertBuffer.count].y = rl.GetMouseY() - brushSize/2
transfertBuffer.commands[transfertBuffer.count].w = brushSize
transfertBuffer.commands[transfertBuffer.count].enabled = rl.IsMouseButtonDown(rl.MOUSE_BUTTON_LEFT)
transfertBuffer.count = transfertBuffer.count + 1
elseif transfertBuffer.count > 0 then
-- Process transfert buffer
-- Send SSBO buffer to GPU
rl.rlUpdateShaderBufferElements(transfertSSBO, transfertBuffer, transfertBufferSize, 0);
-- Process ssbo command
rl.rlEnableShader(golTransfertProgram);
rl.rlBindShaderBuffer(ssboA, 1);
rl.rlBindShaderBuffer(transfertSSBO, 3);
rl.rlComputeShaderDispatch(transfertBuffer.count, 1, 1) -- each GPU unit will process a command
rl.rlDisableShader();
transfertBuffer.count = 0;
else
-- Process game of life logic
rl.rlEnableShader(golLogicProgram)
rl.rlBindShaderBuffer(ssboA, 1)
rl.rlBindShaderBuffer(ssboB, 2)
rl.rlComputeShaderDispatch(GOL_WIDTH / 16, GOL_WIDTH / 16, 1)
rl.rlDisableShader()
ssboA, ssboB = ssboB, ssboA
end
rl.rlBindShaderBuffer(ssboA, 1)
rl.SetShaderValue(golRenderShader, resUniformLoc, resolution, rl.SHADER_UNIFORM_VEC2);
rl.BeginDrawing()
rl.ClearBackground(rl.BLANK)
rl.BeginShaderMode(golRenderShader)
rl.DrawTexture(whiteTex, 0, 0, rl.WHITE)
rl.EndShaderMode()
rl.DrawRectangleLines(
rl.GetMouseX() - brushSize/2,
rl.GetMouseY() - brushSize/2,
brushSize, brushSize,
rl.RED)
rl.DrawText("Use Mouse wheel to increase/decrease brush size", 10, 10, 20, rl.WHITE);
rl.DrawFPS(rl.GetScreenWidth() - 100, 10);
rl.EndDrawing()
end
rl.rlUnloadShaderBuffer(ssboA);
rl.rlUnloadShaderBuffer(ssboB);
rl.rlUnloadShaderBuffer(transfertSSBO);
-- Unload compute shader programs
rl.rlUnloadShaderProgram(golTransfertProgram)
rl.rlUnloadShaderProgram(golLogicProgram)
rl.UnloadTexture(whiteTex) -- Unload white texture
rl.UnloadShader(golRenderShader) -- Unload rendering fragment shader
rl.CloseWindow() -- Close window and OpenGL context

View File

@ -0,0 +1,232 @@
local screenWidth = 1920
local screenHeight = 1080
local preset = 3
local default_sharpness = 1.0
local presets = {
{ 2.0, "Performance" },
{ 1.7, "Balanced" },
{ 1.5, "Quality" },
{ 1.3, "Ultra Quality" },
{ 1.0, "Custom (Native)" }
}
local use_fsr = true
local ratio = presets[preset][1]
local num_blocks = 15
local screenSize = rl.new("Vector2", screenWidth, screenHeight)
local fbWidth = screenWidth / ratio
local fbHeight = screenHeight / ratio
local fbSize = rl.new("Vector2", fbWidth, fbHeight)
rl.SetConfigFlags(rl.FLAG_FULLSCREEN_MODE)
rl.InitWindow(screenWidth, screenHeight, "raylua [shaders] example - AMD FSR")
local render_texture = rl.LoadRenderTexture(fbWidth, fbHeight)
local dest_fb = rl.LoadRenderTexture(screenWidth, screenHeight)
local easu_shader = rl.LoadShader(nil, "resources/fsr/fsrEasu.frag")
local srcSize_loc = rl.GetShaderLocation(easu_shader, "srcSize")
local dstSize_loc = rl.GetShaderLocation(easu_shader, "dstSize")
rl.SetShaderValue(easu_shader, srcSize_loc, fbSize, rl.SHADER_UNIFORM_VEC2)
rl.SetShaderValue(easu_shader, dstSize_loc, screenSize, rl.SHADER_UNIFORM_VEC2)
local rcas_shader = rl.LoadShader(nil, "resources/fsr/fsrRcas.frag")
local sharpness_loc = rl.GetShaderLocation(rcas_shader, "sharpness")
local size_loc = rl.GetShaderLocation(rcas_shader, "dstSize")
local sharpness = rl.new("float[1]", default_sharpness)
rl.SetShaderValue(rcas_shader, sharpness_loc, sharpness, rl.SHADER_UNIFORM_FLOAT)
rl.SetShaderValue(rcas_shader, size_loc, screenSize, rl.SHADER_UNIFORM_VEC2)
local camera = rl.new("Camera3D", {
position = { 30, 20, 30 },
target = { 0, 0, 0 },
up = { 0, 1, 0 },
fovy = 70,
type = rl.CAMERA_PERSPECTIVE
})
local enable_easu = false
local enable_rcas = false
local stop_animation = false
local t = 0.0
local bilinear = false
while not rl.WindowShouldClose() do
if not stop_animation then
t = rl.GetTime()
end
local scale = (2.0 + math.sin(t)) * 0.7
local camera_time = t * 0.3
camera.position.x = math.cos(camera_time) * 40.0
camera.position.z = math.sin(camera_time) * 40.0
if use_fsr then
rl.BeginTextureMode(render_texture)
else
rl.BeginDrawing()
end
rl.BeginMode3D(camera)
rl.ClearBackground(rl.RAYWHITE)
rl.DrawGrid(10, 5.0)
for x=0,num_blocks-1 do
for y=0,num_blocks-1 do
for z=0,num_blocks-1 do
local block_scale = (x + y + z) / 30
local scatter = math.sin(block_scale * 20.0 + t * 4.0)
local cube_pos = rl.new("Vector3",
(x - num_blocks / 2) * (scale * 3.0) + scatter,
(y - num_blocks / 2) * (scale * 2.0) + scatter,
(z - num_blocks / 2) * (scale * 3.0) + scatter)
local cube_color = rl.ColorFromHSV(
(((x + y + z) * 18) % 360), 0.75, 0.9
)
local cube_size = (2.4 - scale) * block_scale
rl.DrawCube(cube_pos, cube_size, cube_size, cube_size, cube_color)
end
end
end
rl.EndMode3D()
if use_fsr then
rl.EndTextureMode()
rl.BeginTextureMode(dest_fb)
rl.ClearBackground(rl.RAYWHITE)
if enable_easu then
rl.BeginShaderMode(easu_shader)
end
rl.DrawTextureEx(render_texture.texture, screenSize, 180, ratio, rl.WHITE)
if enable_easu then
rl.EndShaderMode()
end
rl.EndTextureMode()
rl.BeginDrawing()
rl.ClearBackground(rl.WHITE)
if enable_rcas then
rl.BeginShaderMode(rcas_shader)
end
rl.DrawTextureEx(dest_fb.texture, screenSize, 180, 1.0, rl.WHITE)
if enable_rcas then
rl.EndShaderMode()
end
end
rl.DrawFPS(10, 10)
if use_fsr then
rl.DrawText("EASU", 10, 32, 20, enable_easu and rl.GREEN or rl.RED)
rl.DrawText("RCAS", 10, 54, 20, enable_rcas and rl.GREEN or rl.RED)
rl.DrawText(string.format("sharpness: %.1f", sharpness[0]), 10, 74, 10, rl.BLACK)
rl.DrawText(string.format("Preset: %s (%.1f)", presets[preset][2], ratio), 10, 86, 10, rl.BLACK)
rl.DrawText(string.format("Resolution: %dx%d", fbWidth, fbHeight), 10, 98, 10, rl.BLACK)
rl.DrawText(string.format("Filter: %s", bilinear and "bilinear" or "point"), 10, 110, 10, rl.BLACK)
else
rl.DrawText("NATIVE", 10, 32, 20, rl.BLUE)
end
rl.EndDrawing()
if rl.IsKeyPressed(rl.KEY_E) then
enable_easu = not enable_easu
end
if rl.IsKeyPressed(rl.KEY_R) then
enable_rcas = not enable_rcas
end
if rl.IsKeyPressed(rl.KEY_N) then
use_fsr = not use_fsr
end
if rl.IsKeyPressed(rl.KEY_LEFT) then
sharpness[0] = math.max(0.0, sharpness[0] - 0.1)
rl.SetShaderValue(rcas_shader, sharpness_loc, sharpness, rl.SHADER_UNIFORM_FLOAT)
end
if rl.IsKeyPressed(rl.KEY_RIGHT) then
sharpness[0] = math.min(2.0, sharpness[0] + 0.1)
rl.SetShaderValue(rcas_shader, sharpness_loc, sharpness, rl.SHADER_UNIFORM_FLOAT)
end
if rl.IsKeyPressed(rl.KEY_F) then
bilinear = not bilinear
rl.SetTextureFilter(render_texture.texture,
bilinear and rl.TEXTURE_FILTER_BILINEAR or rl.TEXTURE_FILTER_POINT)
end
local preset_changed = false
if rl.IsKeyPressed(rl.KEY_UP) then
preset_changed = true
preset = preset + 1
if preset == #presets + 1 then
preset = 1
end
end
if rl.IsKeyPressed(rl.KEY_DOWN) then
preset_changed = true
preset = preset - 1
if preset == 0 then
preset = #presets
end
end
if rl.IsKeyPressed(rl.KEY_S) then
stop_animation = not stop_animation
end
if rl.IsKeyPressed(rl.KEY_F11) then
rl.ToggleFullscreen()
end
if preset_changed then
ratio = presets[preset][1]
fbWidth = screenWidth / ratio
fbHeight = screenHeight / ratio
fbSize = rl.new("Vector2", fbWidth, fbHeight)
rl.UnloadRenderTexture(render_texture)
render_texture = rl.LoadRenderTexture(fbWidth, fbHeight)
rl.SetTextureFilter(render_texture.texture,
bilinear and rl.TEXTURE_FILTER_BILINEAR or rl.TEXTURE_FILTER_POINT)
end
end
rl.UnloadRenderTexture(render_texture)
rl.UnloadRenderTexture(dest_fb)
rl.CloseWindow()

View File

@ -0,0 +1,18 @@
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(800, 450, "raylib [core] example - basic window")
local font = rl.LoadFontEx("resources/NotoSans-Medium.ttf", 32, nil, 255)
while not rl.WindowShouldClose() do
rl.BeginDrawing()
rl.DrawFPS(10, 10)
rl.ClearBackground(rl.RAYWHITE)
rl.DrawTextEx(font, "Congrats! You created your first window!", rl.new("Vector2", 174, 200), 32, 0, rl.BLACK)
rl.EndDrawing()
end
rl.CloseWindow()

View File

@ -11,7 +11,7 @@ local fb_data = rl.new("Color[?]", width * height)
framebuffer.width = width
framebuffer.height = height
framebuffer.format = rl.UNCOMPRESSED_R8G8B8A8
framebuffer.format = rl.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
framebuffer.mipmaps = 1
framebuffer.data = fb_data

2
luajit

@ -1 +1 @@
Subproject commit a2a39ea7184f3c8cab9474c6e41f6541265fb362
Subproject commit 5e3c45c43bb0e0f1f2917d432e9d2dba12c42a6e

View File

@ -15,11 +15,14 @@ MODULES := raymath rlgl easings gestures physac raygui
PLATFORM ?= PLATFORM_DESKTOP
GRAPHICS ?= GRAPHICS_API_OPENGL_33
CFLAGS += -D$(GRAPHICS) -D$(PLATFORM)
USE_WAYLAND_DISPLAY ?= FALSE
USE_EXTERNAL_GLFW ?= FALSE
ifeq ($(OS),Windows_NT)
LDFLAGS += -lopengl32 -lgdi32 -lwinmm -static
LDFLAGS_R += -mwindows
EXTERNAL_FILES := src/res/icon.res
else ifeq ($(shell uname),Darwin)
LDFLAGS += -framework CoreVideo -framework IOKit -framework Cocoa \
@ -36,7 +39,7 @@ else
EXTERNAL_FILES :=
endif
all: raylua_s raylua_e luajit raylib
all: raylua_s raylua_e raylua_r luajit raylib
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
@ -61,6 +64,10 @@ raylua_e: src/raylua_e.o src/raylua_self.o src/raylua_builder.o src/lib/miniz.o
$(EXTERNAL_FILES) libraylua.a
$(CC) -o $@ $^ $(LDFLAGS) luajit/src/libluajit.a
raylua_r: src/raylua_e.o src/raylua_self.o src/raylua_builder.o src/lib/miniz.o \
$(EXTERNAL_FILES) libraylua.a
$(CC) -o $@ $^ $(LDFLAGS) $(LDFLAGS_R) luajit/src/libluajit.a
src/res/icon.res: src/res/icon.rc
$(WINDRES) $^ -O coff $@

2
raygui

@ -1 +1 @@
Subproject commit f5bd6c08f8d761b625890e4256339ff93c770ac1
Subproject commit 865bb293764073c01e74314ef647464f1f10fd96

2
raylib

@ -1 +1 @@
Subproject commit e25e380e80a117f2404d65b37700fb620dc1f990
Subproject commit 559ffc633164c30824065a63324ba08efa651ee6

View File

@ -18,60 +18,19 @@ local new = ffi.new
-- Load*() wrappers.
if raylua.loadfile then
local LoadImage = rl.LoadImage
function rl.LoadImage(path)
local LoadMusicStream = rl.LoadMusicStream
function rl.LoadMusicStream(path)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
local ext = "." .. path:gsub(".+%.", "")
return rl.LoadImageFromMemory(ext, f, #f)
return rl.LoadMusicStreamFromMemory(ext, ffi.cast("void *", f), #f)
else
print(("RAYLUA: %s"):format(err))
return LoadImage(path)
return LoadMusicStream(path)
end
end
function rl.LoadTexture(path)
return rl.LoadTextureFromImage(rl.LoadImage(path))
end
local LoadFont, LoadFontEx = rl.LoadFont, rl.LoadFontEx
function rl.LoadFontEx(path, sz, chars, count)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
return rl.LoadFontFromMemory(ext, f, #f, sz, chars, count)
else
return LoadFontEx(sz, chars, count)
end
end
function rl.LoadFont(path)
-- HACK: Hardcoded values (FONT_TTF_DEFAULT_SIZE,
-- FONT_TTF_DEFAULT_NUMCHARS)
return rl.LoadFontEx(path, 32, nil, 95)
end
local LoadWave = rl.LoadWave
function rl.LoadWave(path)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
return rl.LoadWaveFromMemory(ext, f, #f)
else
print(("RAYLUA: %s"):format(err))
return LoadWave(path)
end
end
function rl.LoadSound(path)
return rl.LoadSoundFromWave(rl.LoadWave(path))
end
end
-- math metamethods

File diff suppressed because it is too large Load Diff

View File

@ -24,23 +24,24 @@
#include <rlgl.h>
#include <raymath.h>
#include <easings.h>
#include <gestures.h>
#include <extras/easings.h>
#include <rgestures.h>
#define RAYGUI_SUPPORT_ICONS
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_STATIC
#include <raygui.h>
#define PHYSAC_IMPLEMENTATION
#define PHYSAC_NO_THREADS
#include <physac.h>
#include <extras/physac.h>
#include "autogen/bind.c"
#include "autogen/boot.c"
extern const char *raylua_boot_str;
#ifdef WIN32
__declspec(dllexport)
#endif
void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles,
bool repl)
{
@ -66,6 +67,10 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles,
lua_pushboolean(L, repl);
lua_settable(L, -3);
lua_pushstring(L, "raylib_version");
lua_pushstring(L, RAYLIB_VERSION);
lua_settable(L, -3);
lua_setglobal(L, "raylua");
if (luaL_dostring(L, raylua_boot_lua)) {
@ -74,6 +79,9 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles,
}
}
#ifdef WIN32
__declspec(dllexport)
#endif
int luaopen_raylua(lua_State *L)
{
raylua_boot(L, NULL, NULL, false);

View File

@ -16,7 +16,7 @@
local load = loadstring
raylua.version = "v3.5a"
raylua.version = "v4.0b"
function raylua.repl()
print("> raylua " .. raylua.version .. " <")
@ -45,6 +45,10 @@ end
package.path = "?.lua;?/init.lua"
if os.getenv "LUA_PATH" then
package.path = package.path .. ";" .. os.getenv "LUA_PATH"
end
if raylua.loadfile then
-- Change the second loader to load files using raylua.loadfile
package.loaders[2] = function (name)

View File

@ -62,7 +62,12 @@ int raylua_loadfile(lua_State *L)
return 2;
}
mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0);
if (!mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0)) {
free(buffer);
lua_pushnil(L);
lua_pushfstring(L, "%s: Can't extract file.", path);
return 2;
}
lua_pushlstring(L, buffer, size);
free(buffer);
@ -88,6 +93,69 @@ int raylua_listfiles(lua_State *L)
return 1;
}
unsigned char *raylua_loadFileData(const char *path, unsigned int *out_size)
{
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
if (index == -1) {
printf("RAYLUA: WARN: File not found in payload. '%s'\n", path);
return NULL;
}
mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) {
printf("RAYLUA: WARN: Can't get file information in payload. '%s'\n", path);
return NULL;
}
size_t size = stat.m_uncomp_size;
unsigned char *buffer = RL_MALLOC(size);
if (buffer == NULL) {
printf("RAYLUA: WARN: Can't allocate file buffer. '%s'\n", path);
return NULL;
}
if (!mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0)) {
free(buffer);
printf("RAYLUA: WARN: Can't extract file. '%s'\n", path);
return NULL;
}
*out_size = size;
return buffer;
}
char *raylua_loadFileText(const char *path)
{
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
if (index == -1) {
printf("RAYLUA: WARN: File not found in payload. '%s'\n", path);
return NULL;
}
mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) {
printf("RAYLUA: WARN: Can't get file information in payload. '%s'\n", path);
return NULL;
}
size_t size = stat.m_uncomp_size;
char *buffer = RL_MALLOC(size + 1);
if (buffer == NULL) {
printf("RAYLUA: WARN: Can't allocate file buffer. '%s'\n", path);
return NULL;
}
buffer[size] = '\0';
if (!mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0)) {
free(buffer);
printf("RAYLUA: WARN: Can't extract file. '%s'\n", path);
return NULL;
}
return buffer;
}
static bool raylua_init_payload(FILE *self)
{
mz_zip_zero_struct(&zip_file);
@ -127,6 +195,9 @@ int main(int argc, const char **argv)
return 1;
}
SetLoadFileDataCallback(raylua_loadFileData);
SetLoadFileTextCallback(raylua_loadFileText);
if (!raylua_init_payload(self)) {
#ifdef RAYLUA_NO_BUILDER
puts("RAYLUA: No payload.");

View File

@ -21,10 +21,14 @@ void SetWindowPosition(int x, int y)
void SetWindowMonitor(int monitor)
void SetWindowMinSize(int width, int height)
void SetWindowSize(int width, int height)
void SetWindowOpacity(float opacity)
void *GetWindowHandle(void)
int GetScreenWidth(void)
int GetScreenHeight(void)
int GetRenderWidth(void)
int GetRenderHeight(void)
int GetMonitorCount(void)
int GetCurrentMonitor(void)
Vector2 GetMonitorPosition(int monitor)
int GetMonitorWidth(int monitor)
int GetMonitorHeight(int monitor)
@ -36,6 +40,9 @@ Vector2 GetWindowScaleDPI(void)
const char *GetMonitorName(int monitor)
void SetClipboardText(const char *text)
const char *GetClipboardText(void)
void SwapScreenBuffer(void)
void PollInputEvents(void)
void WaitTime(float ms)
void ShowCursor(void)
void HideCursor(void)
bool IsCursorHidden(void)
@ -51,8 +58,25 @@ void BeginMode3D(Camera3D camera)
void EndMode3D(void)
void BeginTextureMode(RenderTexture2D target)
void EndTextureMode(void)
void BeginShaderMode(Shader shader)
void EndShaderMode(void)
void BeginBlendMode(int mode)
void EndBlendMode(void)
void BeginScissorMode(int x, int y, int width, int height)
void EndScissorMode(void)
void BeginVrStereoMode(VrStereoConfig config)
void EndVrStereoMode(void)
VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device)
void UnloadVrStereoConfig(VrStereoConfig config)
Shader LoadShader(const char *vsFileName, const char *fsFileName)
Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
int GetShaderLocation(Shader shader, const char *uniformName)
int GetShaderLocationAttrib(Shader shader, const char *attribName)
void SetShaderValue(Shader shader, int locIndex, const void *value, int uniformType)
void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniformType, int count)
void SetShaderValueMatrix(Shader shader, int locIndex, Matrix mat)
void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
void UnloadShader(Shader shader)
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
Matrix GetCameraMatrix(Camera camera)
Matrix GetCameraMatrix2D(Camera2D camera)
@ -64,30 +88,33 @@ void SetTargetFPS(int fps)
int GetFPS(void)
float GetFrameTime(void)
double GetTime(void)
void SetConfigFlags(unsigned int flags)
void SetTraceLogLevel(int logType)
void SetTraceLogExit(int logType)
void SetTraceLogCallback(TraceLogCallback callback)
void TraceLog(int logType, const char *text, ...)
void *MemAlloc(int size)
void MemFree(void *ptr)
void TakeScreenshot(const char *fileName)
int GetRandomValue(int min, int max)
uint8_t *LoadFileData(const char *fileName, unsigned int *bytesRead)
void SetRandomSeed(unsigned int seed)
void TakeScreenshot(const char *fileName)
void SetConfigFlags(unsigned int flags)
void TraceLog(int logLevel, const char *text, ...)
void SetTraceLogLevel(int logLevel)
void *MemAlloc(int size)
void *MemRealloc(void *ptr, int size)
void MemFree(void *ptr)
void SetTraceLogCallback(TraceLogCallback callback)
unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
void UnloadFileData(unsigned char *data)
bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
char *LoadFileText(const char *fileName)
void UnloadFileText(unsigned char *text)
void UnloadFileText(char *text)
bool SaveFileText(const char *fileName, char *text)
bool FileExists(const char *fileName)
bool DirectoryExists(const char *dirPath)
bool IsFileExtension(const char *fileName, const char *ext)
int GetFileLength(const char *fileName)
const char *GetFileExtension(const char *fileName)
const char *GetFileName(const char *filePath)
const char *GetFileNameWithoutExt(const char *filePath)
const char *GetDirectoryPath(const char *filePath)
const char *GetPrevDirectoryPath(const char *dirPath)
const char *GetWorkingDirectory(void)
const char *GetApplicationDirectory(void)
char **GetDirectoryFiles(const char *dirPath, int *count)
void ClearDirectoryFiles(void)
bool ChangeDirectory(const char *dir)
@ -95,8 +122,10 @@ bool IsFileDropped(void)
char **GetDroppedFiles(int *count)
void ClearDroppedFiles(void)
long GetFileModTime(const char *fileName)
uint8_t *CompressData(uint8_t *data, int dataLength, int *compDataLength)
uint8_t *DecompressData(uint8_t *compData, int compDataLength, int *dataLength)
unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize)
unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize)
char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize)
bool SaveStorageValue(unsigned int position, int value)
int LoadStorageValue(unsigned int position)
void OpenURL(const char *url)
@ -108,7 +137,6 @@ void SetExitKey(int key)
int GetKeyPressed(void)
int GetCharPressed(void)
bool IsGamepadAvailable(int gamepad)
bool IsGamepadName(int gamepad, const char *name)
const char *GetGamepadName(int gamepad)
bool IsGamepadButtonPressed(int gamepad, int button)
bool IsGamepadButtonDown(int gamepad, int button)
@ -117,6 +145,7 @@ bool IsGamepadButtonUp(int gamepad, int button)
int GetGamepadButtonPressed(void)
int GetGamepadAxisCount(int gamepad)
float GetGamepadAxisMovement(int gamepad, int axis)
int SetGamepadMappings(const char *mappings)
bool IsMouseButtonPressed(int button)
bool IsMouseButtonDown(int button)
bool IsMouseButtonReleased(int button)
@ -124,19 +153,20 @@ bool IsMouseButtonUp(int button)
int GetMouseX(void)
int GetMouseY(void)
Vector2 GetMousePosition(void)
Vector2 GetMouseDelta(void)
void SetMousePosition(int x, int y)
void SetMouseOffset(int offsetX, int offsetY)
void SetMouseScale(float scaleX, float scaleY)
float GetMouseWheelMove(void)
int GetMouseCursor(void)
void SetMouseCursor(int cursor)
int GetTouchX(void)
int GetTouchY(void)
Vector2 GetTouchPosition(int index)
void SetGesturesEnabled(unsigned int gestureFlags)
int GetTouchPointId(int index)
int GetTouchPointCount(void)
void SetGesturesEnabled(unsigned int flags)
bool IsGestureDetected(int gesture)
int GetGestureDetected(void)
int GetTouchPointsCount(void)
float GetGestureHoldDuration(void)
Vector2 GetGestureDragVector(void)
float GetGestureDragAngle(void)
@ -148,23 +178,26 @@ void SetCameraPanControl(int keyPan)
void SetCameraAltControl(int keyAlt)
void SetCameraSmoothZoomControl(int keySmoothZoom)
void SetCameraMoveControls(int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown)
void SetShapesTexture(Texture2D texture, Rectangle source)
void DrawPixel(int posX, int posY, Color color)
void DrawPixelV(Vector2 position, Color color)
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color)
void DrawLineV(Vector2 startPos, Vector2 endPos, Color color)
void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
void DrawLineStrip(Vector2 *points, int pointsCount, Color color)
void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color)
void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color)
void DrawLineStrip(Vector2 *points, int pointCount, Color color)
void DrawCircle(int centerX, int centerY, float radius, Color color)
void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2)
void DrawCircleV(Vector2 center, float radius, Color color)
void DrawCircleLines(int centerX, int centerY, float radius, Color color)
void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color)
void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color)
void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
void DrawRectangle(int posX, int posY, int width, int height, Color color)
void DrawRectangleV(Vector2 position, Vector2 size, Color color)
void DrawRectangleRec(Rectangle rec, Color color)
@ -173,15 +206,16 @@ void DrawRectangleGradientV(int posX, int posY, int width, int height, Color col
void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2)
void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4)
void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color)
void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color)
void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color)
void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, int lineThick, Color color)
void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, float lineThick, Color color)
void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
void DrawTriangleFan(Vector2 *points, int pointsCount, Color color)
void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color)
void DrawTriangleFan(Vector2 *points, int pointCount, Color color)
void DrawTriangleStrip(Vector2 *points, int pointCount, Color color)
void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color)
void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color)
void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color)
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2)
bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2)
bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
@ -189,11 +223,14 @@ bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius)
bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3)
bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold)
Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
Image LoadImage(const char *fileName)
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
Image LoadImageAnim(const char *fileName, int *frames)
Image LoadImageFromMemory(const char *fileType, const uint8_t *fileData, int dataSize)
Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
Image LoadImageFromTexture(Texture2D texture)
Image LoadImageFromScreen(void)
void UnloadImage(Image image)
bool ExportImage(Image image, const char *fileName)
bool ExportImageAsCode(Image image, const char *fileName)
@ -203,7 +240,6 @@ Image GenImageGradientH(int width, int height, Color left, Color right)
Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer)
Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
Image GenImageWhiteNoise(int width, int height, float factor)
Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
Image GenImageCellular(int width, int height, int tileSize)
Image ImageCopy(Image image)
Image ImageFromImage(Image image, Rectangle rec)
@ -232,10 +268,11 @@ void ImageColorContrast(Image *image, float contrast)
void ImageColorBrightness(Image *image, int brightness)
void ImageColorReplace(Image *image, Color color, Color replace)
Color *LoadImageColors(Image image)
Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorsCount)
Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorCount)
void UnloadImageColors(Color *colors)
void UnloadImagePalette(Color *colors)
Rectangle GetImageAlphaBorder(Image image, float threshold)
Color GetImageColor(Image image, int x, int y)
void ImageClearBackground(Image *dst, Color color)
void ImageDrawPixel(Image *dst, int posX, int posY, Color color)
void ImageDrawPixelV(Image *dst, Vector2 position, Color color)
@ -252,17 +289,15 @@ void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSiz
void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
Texture2D LoadTexture(const char *fileName)
Texture2D LoadTextureFromImage(Image image)
TextureCubemap LoadTextureCubemap(Image image, int layoutType)
TextureCubemap LoadTextureCubemap(Image image, int layout)
RenderTexture2D LoadRenderTexture(int width, int height)
void UnloadTexture(Texture2D texture)
void UnloadRenderTexture(RenderTexture2D target)
void UpdateTexture(Texture2D texture, const void *pixels)
void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels)
Image GetTextureData(Texture2D texture)
Image GetScreenData(void)
void GenTextureMipmaps(Texture2D *texture)
void SetTextureFilter(Texture2D texture, int filterMode)
void SetTextureWrap(Texture2D texture, int wrapMode)
void SetTextureFilter(Texture2D texture, int filter)
void SetTextureWrap(Texture2D texture, int wrap)
void DrawTexture(Texture2D texture, int posX, int posY, Color tint)
void DrawTextureV(Texture2D texture, Vector2 position, Color tint)
void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint)
@ -271,6 +306,7 @@ void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangl
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint)
void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint)
void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint)
Color Fade(Color color, float alpha)
int ColorToInt(Color color)
Vector4 ColorNormalize(Color color)
@ -285,22 +321,31 @@ void SetPixelColor(void *dstPtr, Color color, int format)
int GetPixelDataSize(int width, int height, int format)
Font GetFontDefault(void)
Font LoadFont(const char *fileName)
Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount)
Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int glyphCount)
Font LoadFontFromImage(Image image, Color key, int firstChar)
Font LoadFontFromMemory(const char *fileType, const uint8_t *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
CharInfo *LoadFontData(const uint8_t *fileData, int dataSize, int fontSize, int *fontChars, int charsCount, int type)
Image GenImageFontAtlas(const CharInfo *chars, Rectangle **recs, int charsCount, int fontSize, int padding, int packMethod)
void UnloadFontData(CharInfo *chars, int charsCount)
Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount)
GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount, int type)
Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **recs, int glyphCount, int fontSize, int padding, int packMethod)
void UnloadFontData(GlyphInfo *chars, int glyphCount)
void UnloadFont(Font font)
bool ExportFontAsCode(Font font, const char *fileName)
void DrawFPS(int posX, int posY)
void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint)
void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectTint, Color selectBackTint)
void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint)
void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint)
void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint)
int MeasureText(const char *text, int fontSize)
Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing)
int GetGlyphIndex(Font font, int codepoint)
GlyphInfo GetGlyphInfo(Font font, int codepoint)
Rectangle GetGlyphAtlasRec(Font font, int codepoint)
int *LoadCodepoints(const char *text, int *count)
void UnloadCodepoints(int *codepoints)
int GetCodepointCount(const char *text)
int GetCodepoint(const char *text, int *bytesProcessed)
const char *CodepointToUTF8(int codepoint, int *byteSize)
char *TextCodepointsToUTF8(const int *codepoints, int length)
int TextCopy(char *dst, const char *src)
bool TextIsEqual(const char *text1, const char *text2)
unsigned int TextLength(const char *text)
@ -316,120 +361,87 @@ const char *TextToUpper(const char *text)
const char *TextToLower(const char *text)
const char *TextToPascal(const char *text)
int TextToInteger(const char *text)
char *TextToUtf8(int *codepoints, int length)
int *GetCodepoints(const char *text, int *count)
int GetCodepointsCount(const char *text)
int GetNextCodepoint(const char *text, int *bytesProcessed)
const char *CodepointToUtf8(int codepoint, int *byteLength)
void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color)
void DrawPoint3D(Vector3 position, Color color)
void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color)
void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color)
void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color)
void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color)
void DrawCube(Vector3 position, float width, float height, float length, Color color)
void DrawCubeV(Vector3 position, Vector3 size, Color color)
void DrawCubeWires(Vector3 position, float width, float height, float length, Color color)
void DrawCubeWiresV(Vector3 position, Vector3 size, Color color)
void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color)
void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
void DrawSphere(Vector3 centerPos, float radius, Color color)
void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color)
void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color)
void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color)
void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color)
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color)
void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color)
void DrawPlane(Vector3 centerPos, Vector2 size, Color color)
void DrawRay(Ray ray, Color color)
void DrawGrid(int slices, float spacing)
void DrawGizmo(Vector3 position)
Model LoadModel(const char *fileName)
Model LoadModelFromMesh(Mesh mesh)
void UnloadModel(Model model)
void UnloadModelKeepMeshes(Model model)
Mesh *LoadMeshes(const char *fileName, int *meshCount)
bool ExportMesh(Mesh mesh, const char *fileName)
BoundingBox GetModelBoundingBox(Model model)
void DrawModel(Model model, Vector3 position, float scale, Color tint)
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
void DrawModelWires(Model model, Vector3 position, float scale, Color tint)
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
void DrawBoundingBox(BoundingBox box, Color color)
void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint)
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint)
void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint)
void UploadMesh(Mesh *mesh, bool dynamic)
void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize, int offset)
void UnloadMesh(Mesh mesh)
Material *LoadMaterials(const char *fileName, int *materialCount)
Material LoadMaterialDefault(void)
void UnloadMaterial(Material material)
void SetMaterialTexture(Material *material, int mapType, Texture2D texture)
void SetModelMeshMaterial(Model *model, int meshId, int materialId)
ModelAnimation *LoadModelAnimations(const char *fileName, int *animsCount)
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
void UnloadModelAnimation(ModelAnimation anim)
bool IsModelAnimationValid(Model model, ModelAnimation anim)
void DrawMesh(Mesh mesh, Material material, Matrix transform)
void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances)
bool ExportMesh(Mesh mesh, const char *fileName)
BoundingBox GetMeshBoundingBox(Mesh mesh)
void GenMeshTangents(Mesh *mesh)
void GenMeshBinormals(Mesh *mesh)
Mesh GenMeshPoly(int sides, float radius)
Mesh GenMeshPlane(float width, float length, int resX, int resZ)
Mesh GenMeshCube(float width, float height, float length)
Mesh GenMeshSphere(float radius, int rings, int slices)
Mesh GenMeshHemiSphere(float radius, int rings, int slices)
Mesh GenMeshCylinder(float radius, float height, int slices)
Mesh GenMeshCone(float radius, float height, int slices)
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
BoundingBox MeshBoundingBox(Mesh mesh)
void MeshTangents(Mesh *mesh)
void MeshBinormals(Mesh *mesh)
void MeshNormalsSmooth(Mesh *mesh)
void DrawModel(Model model, Vector3 position, float scale, Color tint)
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
void DrawModelWires(Model model, Vector3 position, float scale, Color tint)
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
void DrawBoundingBox(BoundingBox box, Color color)
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint)
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 center, float size, Color tint)
Material *LoadMaterials(const char *fileName, int *materialCount)
Material LoadMaterialDefault(void)
void UnloadMaterial(Material material)
void SetMaterialTexture(Material *material, int mapType, Texture2D texture)
void SetModelMeshMaterial(Model *model, int meshId, int materialId)
ModelAnimation *LoadModelAnimations(const char *fileName, unsigned int *animCount)
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
void UnloadModelAnimation(ModelAnimation anim)
void UnloadModelAnimations(ModelAnimation* animations, unsigned int count)
bool IsModelAnimationValid(Model model, ModelAnimation anim)
bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2)
bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2)
bool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius)
bool CheckCollisionRaySphere(Ray ray, Vector3 center, float radius)
bool CheckCollisionRaySphereEx(Ray ray, Vector3 center, float radius, Vector3 *collisionPoint)
bool CheckCollisionRayBox(Ray ray, BoundingBox box)
RayHitInfo GetCollisionRayMesh(Ray ray, Mesh mesh, Matrix transform)
RayHitInfo GetCollisionRayModel(Ray ray, Model model)
RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight)
Shader LoadShader(const char *vsFileName, const char *fsFileName)
Shader LoadShaderCode(const char *vsCode, const char *fsCode)
void UnloadShader(Shader shader)
Shader GetShaderDefault(void)
Texture2D GetTextureDefault(void)
Texture2D GetShapesTexture(void)
Rectangle GetShapesTextureRec(void)
void SetShapesTexture(Texture2D texture, Rectangle source)
int GetShaderLocation(Shader shader, const char *uniformName)
int GetShaderLocationAttrib(Shader shader, const char *attribName)
void SetShaderValue(Shader shader, int uniformLoc, const void *value, int uniformType)
void SetShaderValueV(Shader shader, int uniformLoc, const void *value, int uniformType, int count)
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
void SetShaderValueTexture(Shader shader, int uniformLoc, Texture2D texture)
void SetMatrixProjection(Matrix proj)
void SetMatrixModelview(Matrix view)
Matrix GetMatrixModelview(void)
Matrix GetMatrixProjection(void)
TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int size, int format)
TextureCubemap GenTextureIrradiance(Shader shader, TextureCubemap cubemap, int size)
TextureCubemap GenTexturePrefilter(Shader shader, TextureCubemap cubemap, int size)
Texture2D GenTextureBRDF(Shader shader, int size)
void BeginShaderMode(Shader shader)
void EndShaderMode(void)
void BeginBlendMode(int mode)
void EndBlendMode(void)
void InitVrSimulator(void)
void CloseVrSimulator(void)
void UpdateVrTracking(Camera *camera)
void SetVrConfiguration(VrDeviceInfo info, Shader distortion)
bool IsVrSimulatorReady(void)
void ToggleVrMode(void)
void BeginVrDrawing(void)
void EndVrDrawing(void)
RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix transform)
RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
void InitAudioDevice(void)
void CloseAudioDevice(void)
bool IsAudioDeviceReady(void)
void SetMasterVolume(float volume)
Wave LoadWave(const char *fileName)
Wave LoadWaveFromMemory(const char *fileType, const uint8_t *fileData, int dataSize)
Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
Sound LoadSound(const char *fileName)
Sound LoadSoundFromWave(Wave wave)
void UpdateSound(Sound sound, const void *data, int samplesCount)
void UpdateSound(Sound sound, const void *data, int sampleCount)
void UnloadWave(Wave wave)
void UnloadSound(Sound sound)
bool ExportWave(Wave wave, const char *fileName)
@ -444,26 +456,30 @@ int GetSoundsPlaying(void)
bool IsSoundPlaying(Sound sound)
void SetSoundVolume(Sound sound, float volume)
void SetSoundPitch(Sound sound, float pitch)
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
void SetSoundPan(Sound sound, float pan)
Wave WaveCopy(Wave wave)
void WaveCrop(Wave *wave, int initSample, int finalSample)
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
float *LoadWaveSamples(Wave wave)
void UnloadWaveSamples(float *samples)
Music LoadMusicStream(const char *fileName)
Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char* data, int dataSize)
void UnloadMusicStream(Music music)
void PlayMusicStream(Music music)
bool IsMusicStreamPlaying(Music music)
void UpdateMusicStream(Music music)
void StopMusicStream(Music music)
void PauseMusicStream(Music music)
void ResumeMusicStream(Music music)
bool IsMusicPlaying(Music music)
void SeekMusicStream(Music music, float position)
void SetMusicVolume(Music music, float volume)
void SetMusicPan(Music music, float pan)
void SetMusicPitch(Music music, float pitch)
float GetMusicTimeLength(Music music)
float GetMusicTimePlayed(Music music)
AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels)
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
void CloseAudioStream(AudioStream stream)
AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels)
void UnloadAudioStream(AudioStream stream)
void UpdateAudioStream(AudioStream stream, const void *data, int frameCount)
bool IsAudioStreamProcessed(AudioStream stream)
void PlayAudioStream(AudioStream stream)
void PauseAudioStream(AudioStream stream)
@ -472,4 +488,8 @@ bool IsAudioStreamPlaying(AudioStream stream)
void StopAudioStream(AudioStream stream)
void SetAudioStreamVolume(AudioStream stream, float volume)
void SetAudioStreamPitch(AudioStream stream, float pitch)
void SetAudioStreamPan(AudioStream stream, float pan)
void SetAudioStreamBufferSizeDefault(int size)
void SetAudioStreamCallback(AudioStream stream, AudioCallback callback)
void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor)
void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processor)

View File

@ -0,0 +1,139 @@
local json = require "json"
local content = io.open(arg[1], "r"):read "*a"
local t = json.decode(content)
print "---@diagnostic disable"
print "---raylib-lua binding"
print "rl = {}"
local ffi_type_list = {}
local function luaify(t)
-- strings
for _,v in ipairs { "void %*", "char %*" } do
if string.find(t, v) then
return 'string|lightuserdata'
end
end
for _,v in ipairs { "char" } do
if string.find(t, v) then
return "number|string[]"
end
end
for _,v in ipairs { "int", "long", "float", "double" } do
if string.find(t, v) then
return "number"
end
end
local t = t:gsub(" ", "_"):gsub("*", "_ptr"):gsub("__", "_")
if t:find "_ptr" then
t = t .. "|lightuserdata"
end
return t
end
for _,enum in ipairs(t.enums) do
print("---@alias " .. enum.name)
for _,v in pairs(enum.values) do
print(string.format("---| '%s'", v.name))
end
if enum.description ~= "" then
print("---" .. enum.description)
end
print ""
for _,v in pairs(enum.values) do
if v.description ~= "" then
print("---" .. v.description)
end
print(string.format("rl.%s = %u", v.name, v.value))
end
end
for _,struct in ipairs(t.structs) do
print(string.format("---@class %s%s", struct.name,
(struct.description ~= "") and string.format(" @ %s", struct.description) or ""))
print(string.format("---@alias %s_ptr %s", struct.name, struct.name))
print(string.format("---@alias %s_ptr_ptr %s", struct.name, struct.name))
if struct.name == "Texture" then
print "---@alias Texture2D Texture"
end
if struct.name == "RenderTexture" then
print "---@alias RenderTexture2D RenderTexture"
end
ffi_type_list[#ffi_type_list+1] = struct.name
for _,field in pairs(struct.fields) do
for n in field.name:gmatch "([^, ]+),?" do
local arraySize = n:match "%[(.-)%]"
if arraySize then
n = n:match("(%S-)%[.-%]")
field.type = string.format("%s[]", luaify(field.type), arraySize)
end
print(string.format('---@field %s %s%s', n, luaify(field.type),
(field.description ~= "") and string.format(" # %s", field.description) or ""))
end
end
print(string.format('---Constructed using `rl.new("%s", ...)`', struct.name))
print(string.format("local %s = {}", struct.name))
end
for _,func in ipairs(t.functions) do
local arraySize
local args = {}
local vla = false
for i,param in ipairs(func.params or {}) do
if param.name ~= "" then
arraySize = param.name:match "%[(.-)%]"
if arraySize then
param.name = param.name:match("(%S-)%[.-%]")
param.type = string.format("%s[%d]", param.type, arraySize)
end
arraySize = param.name:match "%[(.-)%]"
if arraySize then
param.name = param.name:match("(%S-)%[.-%]")
param.type = string.format("%s[%d]", luaify(param.type), arraySize)
end
print(string.format('---@param %s %s', param.name, luaify(param.type)))
args[#args + 1] = param.name
else
vla = true
end
end
if func.returnType and func.returnType ~= "void" then
print(string.format('---@return %s', luaify(func.returnType)))
end
if vla then
print "---@vararg any"
end
if func.description ~= "" then
print("---" .. func.description)
end
print(string.format("function rl.%s(%s%s) end", func.name, table.concat(args, ","), vla and ", ..." or ""))
end
print "---Create a new variable of ffi type `t`"
for i,t in ipairs(ffi_type_list) do
print(string.format([[---@overload fun(t: '"%s"', ...): %s]], t, t))
end
print("function rl.new(...) end")

388
tools/autocomplete/json.lua Normal file
View File

@ -0,0 +1,388 @@
--
-- json.lua
--
-- Copyright (c) 2020 rxi
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--
local json = { _version = "0.1.2" }
-------------------------------------------------------------------------------
-- Encode
-------------------------------------------------------------------------------
local encode
local escape_char_map = {
[ "\\" ] = "\\",
[ "\"" ] = "\"",
[ "\b" ] = "b",
[ "\f" ] = "f",
[ "\n" ] = "n",
[ "\r" ] = "r",
[ "\t" ] = "t",
}
local escape_char_map_inv = { [ "/" ] = "/" }
for k, v in pairs(escape_char_map) do
escape_char_map_inv[v] = k
end
local function escape_char(c)
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
end
local function encode_nil(val)
return "null"
end
local function encode_table(val, stack)
local res = {}
stack = stack or {}
-- Circular reference?
if stack[val] then error("circular reference") end
stack[val] = true
if rawget(val, 1) ~= nil or next(val) == nil then
-- Treat as array -- check keys are valid and it is not sparse
local n = 0
for k in pairs(val) do
if type(k) ~= "number" then
error("invalid table: mixed or invalid key types")
end
n = n + 1
end
if n ~= #val then
error("invalid table: sparse array")
end
-- Encode
for i, v in ipairs(val) do
table.insert(res, encode(v, stack))
end
stack[val] = nil
return "[" .. table.concat(res, ",") .. "]"
else
-- Treat as an object
for k, v in pairs(val) do
if type(k) ~= "string" then
error("invalid table: mixed or invalid key types")
end
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
end
stack[val] = nil
return "{" .. table.concat(res, ",") .. "}"
end
end
local function encode_string(val)
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
end
local function encode_number(val)
-- Check for NaN, -inf and inf
if val ~= val or val <= -math.huge or val >= math.huge then
error("unexpected number value '" .. tostring(val) .. "'")
end
return string.format("%.14g", val)
end
local type_func_map = {
[ "nil" ] = encode_nil,
[ "table" ] = encode_table,
[ "string" ] = encode_string,
[ "number" ] = encode_number,
[ "boolean" ] = tostring,
}
encode = function(val, stack)
local t = type(val)
local f = type_func_map[t]
if f then
return f(val, stack)
end
error("unexpected type '" .. t .. "'")
end
function json.encode(val)
return ( encode(val) )
end
-------------------------------------------------------------------------------
-- Decode
-------------------------------------------------------------------------------
local parse
local function create_set(...)
local res = {}
for i = 1, select("#", ...) do
res[ select(i, ...) ] = true
end
return res
end
local space_chars = create_set(" ", "\t", "\r", "\n")
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
local literals = create_set("true", "false", "null")
local literal_map = {
[ "true" ] = true,
[ "false" ] = false,
[ "null" ] = nil,
}
local function next_char(str, idx, set, negate)
for i = idx, #str do
if set[str:sub(i, i)] ~= negate then
return i
end
end
return #str + 1
end
local function decode_error(str, idx, msg)
local line_count = 1
local col_count = 1
for i = 1, idx - 1 do
col_count = col_count + 1
if str:sub(i, i) == "\n" then
line_count = line_count + 1
col_count = 1
end
end
error( string.format("%s at line %d col %d", msg, line_count, col_count) )
end
local function codepoint_to_utf8(n)
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
local f = math.floor
if n <= 0x7f then
return string.char(n)
elseif n <= 0x7ff then
return string.char(f(n / 64) + 192, n % 64 + 128)
elseif n <= 0xffff then
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
elseif n <= 0x10ffff then
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
f(n % 4096 / 64) + 128, n % 64 + 128)
end
error( string.format("invalid unicode codepoint '%x'", n) )
end
local function parse_unicode_escape(s)
local n1 = tonumber( s:sub(1, 4), 16 )
local n2 = tonumber( s:sub(7, 10), 16 )
-- Surrogate pair?
if n2 then
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
else
return codepoint_to_utf8(n1)
end
end
local function parse_string(str, i)
local res = ""
local j = i + 1
local k = j
while j <= #str do
local x = str:byte(j)
if x < 32 then
decode_error(str, j, "control character in string")
elseif x == 92 then -- `\`: Escape
res = res .. str:sub(k, j - 1)
j = j + 1
local c = str:sub(j, j)
if c == "u" then
local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1)
or str:match("^%x%x%x%x", j + 1)
or decode_error(str, j - 1, "invalid unicode escape in string")
res = res .. parse_unicode_escape(hex)
j = j + #hex
else
if not escape_chars[c] then
decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string")
end
res = res .. escape_char_map_inv[c]
end
k = j + 1
elseif x == 34 then -- `"`: End of string
res = res .. str:sub(k, j - 1)
return res, j + 1
end
j = j + 1
end
decode_error(str, i, "expected closing quote for string")
end
local function parse_number(str, i)
local x = next_char(str, i, delim_chars)
local s = str:sub(i, x - 1)
local n = tonumber(s)
if not n then
decode_error(str, i, "invalid number '" .. s .. "'")
end
return n, x
end
local function parse_literal(str, i)
local x = next_char(str, i, delim_chars)
local word = str:sub(i, x - 1)
if not literals[word] then
decode_error(str, i, "invalid literal '" .. word .. "'")
end
return literal_map[word], x
end
local function parse_array(str, i)
local res = {}
local n = 1
i = i + 1
while 1 do
local x
i = next_char(str, i, space_chars, true)
-- Empty / end of array?
if str:sub(i, i) == "]" then
i = i + 1
break
end
-- Read token
x, i = parse(str, i)
res[n] = x
n = n + 1
-- Next token
i = next_char(str, i, space_chars, true)
local chr = str:sub(i, i)
i = i + 1
if chr == "]" then break end
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
end
return res, i
end
local function parse_object(str, i)
local res = {}
i = i + 1
while 1 do
local key, val
i = next_char(str, i, space_chars, true)
-- Empty / end of object?
if str:sub(i, i) == "}" then
i = i + 1
break
end
-- Read key
if str:sub(i, i) ~= '"' then
decode_error(str, i, "expected string for key")
end
key, i = parse(str, i)
-- Read ':' delimiter
i = next_char(str, i, space_chars, true)
if str:sub(i, i) ~= ":" then
decode_error(str, i, "expected ':' after key")
end
i = next_char(str, i + 1, space_chars, true)
-- Read value
val, i = parse(str, i)
-- Set
res[key] = val
-- Next token
i = next_char(str, i, space_chars, true)
local chr = str:sub(i, i)
i = i + 1
if chr == "}" then break end
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
end
return res, i
end
local char_func_map = {
[ '"' ] = parse_string,
[ "0" ] = parse_number,
[ "1" ] = parse_number,
[ "2" ] = parse_number,
[ "3" ] = parse_number,
[ "4" ] = parse_number,
[ "5" ] = parse_number,
[ "6" ] = parse_number,
[ "7" ] = parse_number,
[ "8" ] = parse_number,
[ "9" ] = parse_number,
[ "-" ] = parse_number,
[ "t" ] = parse_literal,
[ "f" ] = parse_literal,
[ "n" ] = parse_literal,
[ "[" ] = parse_array,
[ "{" ] = parse_object,
}
parse = function(str, idx)
local chr = str:sub(idx, idx)
local f = char_func_map[chr]
if f then
return f(str, idx)
end
decode_error(str, idx, "unexpected character '" .. chr .. "'")
end
function json.decode(str)
if type(str) ~= "string" then
error("expected argument of type string, got " .. type(str))
end
local res, idx = parse(str, next_char(str, 1, space_chars, true))
idx = next_char(str, idx, space_chars, true)
if idx <= #str then
decode_error(str, idx, "trailing garbage")
end
return res
end
return json

File diff suppressed because it is too large Load Diff

View File

@ -8,24 +8,39 @@ local keywords = {
local structs = {
"Vector2", "Vector3", "Vector4", "Quaternion",
"Matrix", "Color", "Rectangle", "Image", "Texture", "Texture2D",
"RenderTexture", "NPatchInfo", "CharInfo", "Font",
"RenderTexture", "NPatchInfo", "GlyphInfo", "Font",
"Camera", "Camera2D", "Mesh", "Shader", "MaterialMap",
"Material", "Model", "Transform", "BoneInfo", "ModelAnimation",
"Ray", "RayHitInfo", "BoundingBox", "Wave", "Sound", "Music",
"Ray", "RayCollision", "BoundingBox", "Wave", "Sound", "Music",
"AudioStream", "VrDeviceInfo", "Camera3D", "RenderTexture2D",
"TextureCubemap", "TraceLogCallback", "PhysicsBody",
"GestureEvent", "GuiStyle", "GuiTextBoxState"
"GestureEvent", "GuiStyle", "GuiTextBoxState",
"TraceLogCallback", "VertexBuffer", "DrawCall", "RenderBatch",
"ShaderAttributeDataType", "MaterialMapIndex", "VrStereoConfig",
"AudioCallback"
}
local rl_structs = {
"rlTraceLogLevel", "rlPixelFormat", "rlTextureFilter",
"rlBlendMode", "rlShaderLocationIndex", "rlShaderUniformDataType",
"rlShaderAttributeDataType", "rlFramebufferAttachType",
"rlFramebufferAttachTextureType", "rlVertexBuffer", "rlDrawCall",
"rlRenderBatch"
}
local functions = {}
local proto = {}
local counter = 0
local file = io.open(arg[1], "wb")
local modules = { "api" }
local funcname
local custom_support = {
["rlgl"] = function (line)
return line:gsub("[%s*]+(rl%w+)", function (part)
return line:gsub("([%s*]+)(rl%w+)", function (pre, part)
functions[#functions + 1] = part
funcname = part
counter = counter + 1
if counter == 2 then
@ -37,58 +52,10 @@ local custom_support = {
end
}
local file = io.open(arg[1], "wb")
local modules = { "api" }
for i=2,#arg do
modules[i] = arg[i]
end
for _,modname in ipairs(modules) do
for line in io.lines("tools/" .. modname .. ".h") do
if custom_support[modname] then
line = custom_support[modname](line)
end
line = line:gsub("(%W)([%l%d][%w_]*)", function (before, part)
for i,keyword in ipairs(keywords) do
if part == keyword
or part == "t" then -- uintX_t workaround
return before .. part
end
end
return before
end)
line = line:gsub("%u%w+", function (part)
for i,struct in ipairs(structs) do
if part == struct then
return part
end
end
functions[#functions + 1] = part
counter = counter + 1
if count == 2 then
print("WARN: Multiple matches for: " .. line)
end
return "(*)"
end)
-- Strip spaces
line = line:gsub("([(),*.])%s+(%w)", function (a, b) return a .. b end)
line = line:gsub("(%w)%s+([(),*.])", function (a, b) return a .. b end)
proto[#proto + 1] = line
end
end
assert(#proto == #functions, "Mismatching proto and function count : " ..
#proto .. " ~= " .. #functions)
file:write [[
struct raylua_bind_entry {
const char *name;
@ -99,12 +66,76 @@ struct raylua_bind_entry {
struct raylua_bind_entry raylua_entries[] = {
]]
for i=1,#proto do
local name, proto = functions[i], proto[i]
file:write(string.format('{ "%s", "%s", &%s },\n', name, proto, name))
for _,modname in ipairs(modules) do
for line in io.lines("tools/" .. modname .. ".h") do
if line:sub(1, 2) ~= "//" then
if line:sub(1, 1) == "#" then
file:write(" " .. line .. "\n")
else
counter = 0
funcname = nil
if custom_support[modname] then
line = custom_support[modname](line)
end
line = line:gsub("(%W)([%l%d][%w_]*)", function (before, part)
for i,keyword in ipairs(keywords) do
if part == keyword
or part == "t" then -- uintX_t workaround
return before .. part
end
end
for i,s in ipairs(rl_structs) do
if part == s then
return before .. part
end
end
return before
end)
line = line:gsub("%u%w+", function (part)
for i,struct in ipairs(structs) do
if part == struct then
return part
end
end
functions[#functions + 1] = part
funcname = part
counter = counter + 1
if counter == 2 then
print("WARN: Multiple matches for: " .. line)
end
return "(*)"
end)
-- Strip spaces
line = line:gsub("([(),*.])%s+(%w)", function (a, b) return a .. b end)
line = line:gsub("(%w)%s+([(),*.])", function (a, b) return a .. b end)
proto[#proto + 1] = line
if funcname and line then
file:write(string.format(' { "%s", "%s", &%s },\n', funcname, line, funcname))
elseif counter == 0 then
print("WARN: Invalid entry", funcname, line)
end
end
end
end
end
file:write '{ NULL, NULL, NULL },\n'
assert(#proto == #functions, "Mismatching proto and function count : " ..
#proto .. " ~= " .. #functions)
print(string.format("Bound %d functions.", #proto))
file:write ' { NULL, NULL, NULL },\n'
file:write "};\n"
file:close()

View File

@ -1,20 +1,19 @@
void InitPhysics(void)
void RunPhysicsStep(void)
void UpdatePhysics(void)
void ResetPhysics(void)
void ClosePhysics(void)
void SetPhysicsTimeStep(double delta)
bool IsPhysicsEnabled(void)
void SetPhysicsGravity(float x, float y)
PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density)
PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density)
PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density)
void DestroyPhysicsBody(PhysicsBody body)
void PhysicsAddForce(PhysicsBody body, Vector2 force)
void PhysicsAddTorque(PhysicsBody body, float amount)
void PhysicsShatter(PhysicsBody body, Vector2 position, float force)
int GetPhysicsBodiesCount(void)
void SetPhysicsBodyRotation(PhysicsBody body, float radians)
PhysicsBody GetPhysicsBody(int index)
int GetPhysicsBodiesCount(void)
int GetPhysicsShapeType(int index)
int GetPhysicsShapeVerticesCount(int index)
Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex)
void SetPhysicsBodyRotation(PhysicsBody body, float radians)
void DestroyPhysicsBody(PhysicsBody body)
void ResetPhysics(void)
void ClosePhysics(void)
Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex)

View File

@ -2,6 +2,7 @@ void GuiEnable(void)
void GuiDisable(void)
void GuiLock(void)
void GuiUnlock(void)
bool GuiIsLocked(void)
void GuiFade(float alpha)
void GuiSetState(int state)
int GuiGetState(void)
@ -9,20 +10,14 @@ void GuiSetFont(Font font)
Font GuiGetFont(void)
void GuiSetStyle(int control, int property, int value)
int GuiGetStyle(int control, int property)
void GuiEnableTooltip(void)
void GuiDisableTooltip(void)
void GuiSetTooltip(const char *tooltip)
void GuiClearTooltip(void)
bool GuiWindowBox(Rectangle bounds, const char *title)
void GuiGroupBox(Rectangle bounds, const char *text)
void GuiLine(Rectangle bounds, const char *text)
void GuiPanel(Rectangle bounds)
Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll)
void GuiPanel(Rectangle bounds, const char *text)
Rectangle GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll)
void GuiLabel(Rectangle bounds, const char *text)
bool GuiButton(Rectangle bounds, const char *text)
bool GuiLabelButton(Rectangle bounds, const char *text)
bool GuiImageButton(Rectangle bounds, const char *text, Texture2D texture)
bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rectangle texSource)
bool GuiToggle(Rectangle bounds, const char *text, bool active)
int GuiToggleGroup(Rectangle bounds, const char *text, int active)
bool GuiCheckBox(Rectangle bounds, const char *text, bool checked)
@ -37,23 +32,23 @@ float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight
float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue)
void GuiStatusBar(Rectangle bounds, const char *text)
void GuiDummyRec(Rectangle bounds, const char *text)
int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs)
Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs)
int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active)
int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active)
int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons)
int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text)
Color GuiColorPicker(Rectangle bounds, Color color)
Color GuiColorPanel(Rectangle bounds, Color color)
float GuiColorBarAlpha(Rectangle bounds, float alpha)
float GuiColorBarHue(Rectangle bounds, float value)
int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, int *secretViewActive)
Color GuiColorPicker(Rectangle bounds, const char *text, Color color)
Color GuiColorPanel(Rectangle bounds, const char *text, Color color)
float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha)
float GuiColorBarHue(Rectangle bounds, const char *text, float value)
void GuiLoadStyle(const char *fileName)
void GuiLoadStyleDefault(void)
const char *GuiIconText(int iconId, const char *text)
void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color)
void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color)
unsigned int *GuiGetIcons(void)
unsigned int *GuiGetIconData(int iconId)
void GuiSetIconData(int iconId, unsigned int *data)
void GuiSetIconScale(unsigned int scale)
void GuiSetIconPixel(int iconId, int x, int y)
void GuiClearIconPixel(int iconId, int x, int y)
bool GuiCheckIconPixel(int iconId, int x, int y)
bool GuiCheckIconPixel(int iconId, int x, int y)

View File

@ -12,12 +12,14 @@ float Vector2Length(Vector2 v)
float Vector2LengthSqr(Vector2 v)
float Vector2DotProduct(Vector2 v1, Vector2 v2)
float Vector2Distance(Vector2 v1, Vector2 v2)
float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
float Vector2Angle(Vector2 v1, Vector2 v2)
Vector2 Vector2Scale(Vector2 v, float scale)
Vector2 Vector2Multiply(Vector2 v1, Vector2 v2)
Vector2 Vector2Negate(Vector2 v)
Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
Vector2 Vector2Normalize(Vector2 v)
Vector2 Vector2Transform(Vector2 v, Matrix mat)
Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount)
Vector2 Vector2Reflect(Vector2 v, Vector2 normal)
Vector2 Vector2Rotate(Vector2 v, float degs)
@ -36,6 +38,8 @@ float Vector3Length(const Vector3 v)
float Vector3LengthSqr(const Vector3 v)
float Vector3DotProduct(Vector3 v1, Vector3 v2)
float Vector3Distance(Vector3 v1, Vector3 v2)
float Vector3DistanceSqr(Vector3 v1, Vector3 v2)
Vector2 Vector3Angle(Vector3 v1, Vector3 v2)
Vector3 Vector3Negate(Vector3 v)
Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
Vector3 Vector3Normalize(Vector3 v)
@ -52,7 +56,6 @@ float MatrixDeterminant(Matrix mat)
float MatrixTrace(Matrix mat)
Matrix MatrixTranspose(Matrix mat)
Matrix MatrixInvert(Matrix mat)
Matrix MatrixNormalize(Matrix mat)
Matrix MatrixIdentity(void)
Matrix MatrixAdd(Matrix left, Matrix right)
Matrix MatrixSubtract(Matrix left, Matrix right)
@ -89,7 +92,7 @@ Quaternion QuaternionFromMatrix(Matrix mat)
Matrix QuaternionToMatrix(Quaternion q)
Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
Quaternion QuaternionFromEuler(float roll, float pitch, float yaw)
Quaternion QuaternionFromEuler(float pitch, float yaw, float roll)
Vector3 QuaternionToEuler(Quaternion q)
Quaternion QuaternionTransform(Quaternion q, Matrix mat)
Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)
Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)

View File

@ -3,7 +3,7 @@ void rlPushMatrix(void)
void rlPopMatrix(void)
void rlLoadIdentity(void)
void rlTranslatef(float x, float y, float z)
void rlRotatef(float angleDeg, float x, float y, float z)
void rlRotatef(float angle, float x, float y, float z)
void rlScalef(float x, float y, float z)
void rlMultMatrixf(float *matf)
void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar)
@ -19,13 +19,31 @@ void rlNormal3f(float x, float y, float z)
void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void rlColor3f(float x, float y, float z)
void rlColor4f(float x, float y, float z, float w)
bool rlEnableVertexArray(unsigned int vaoId)
void rlDisableVertexArray(void)
void rlEnableVertexBuffer(unsigned int id)
void rlDisableVertexBuffer(void)
void rlEnableVertexBufferElement(unsigned int id)
void rlDisableVertexBufferElement(void)
void rlEnableVertexAttribute(unsigned int index)
void rlDisableVertexAttribute(unsigned int index)
#if defined(GRAPHICS_API_OPENGL_11)
void rlEnableStatePointer(int vertexAttribType, void *buffer)
void rlDisableStatePointer(int vertexAttribType)
#endif
void rlActiveTextureSlot(int slot)
void rlEnableTexture(unsigned int id)
void rlDisableTexture(void)
void rlEnableTextureCubemap(unsigned int id)
void rlDisableTextureCubemap(void)
void rlTextureParameters(unsigned int id, int param, int value)
void rlEnableShader(unsigned int id)
void rlDisableShader(void)
void rlEnableFramebuffer(unsigned int id)
void rlDisableFramebuffer(void)
void rlActiveDrawBuffers(int count)
void rlEnableColorBlend(void)
void rlDisableColorBlend(void)
void rlEnableDepthTest(void)
void rlDisableDepthTest(void)
void rlEnableDepthMask(void)
@ -41,35 +59,88 @@ void rlSetLineWidth(float width)
float rlGetLineWidth(void)
void rlEnableSmoothLines(void)
void rlDisableSmoothLines(void)
void rlEnableStereoRender(void)
void rlDisableStereoRender(void)
bool rlIsStereoRenderEnabled(void)
void rlClearColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void rlClearScreenBuffers(void)
void rlUpdateBuffer(int bufferId, void *data, int dataSize)
unsigned int rlLoadAttribBuffer(unsigned int vaoId, int shaderLoc, void *buffer, int size, bool dynamic)
void rlCheckErrors(void)
void rlSetBlendMode(int mode)
void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation)
void rlglInit(int width, int height)
void rlglClose(void)
void rlglDraw(void)
void rlCheckErrors(void)
int rlGetVersion(void)
bool rlCheckBufferLimit(int vCount)
void rlSetDebugMarker(const char *text)
void rlSetBlendMode(int glSrcFactor, int glDstFactor, int glEquation)
void rlLoadExtensions(void *loader)
unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
int rlGetVersion(void)
int rlGetFramebufferWidth(void)
int rlGetFramebufferHeight(void)
unsigned int rlGetTextureIdDefault(void)
unsigned int rlGetShaderIdDefault(void)
int *rlGetShaderLocsDefault(void)
rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
void rlUnloadRenderBatch(rlRenderBatch batch)
void rlDrawRenderBatch(rlRenderBatch *batch)
void rlSetRenderBatchActive(rlRenderBatch *batch)
void rlDrawRenderBatchActive(void)
bool rlCheckRenderBatchLimit(int vCount)
void rlSetTexture(unsigned int id)
unsigned int rlLoadVertexArray(void)
unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic)
unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic)
void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset)
void rlUpdateVertexBufferElements(unsigned int id, const void *data, int dataSize, int offset)
void rlUnloadVertexArray(unsigned int vaoId)
void rlUnloadVertexBuffer(unsigned int vboId)
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
void rlSetVertexAttributeDivisor(unsigned int index, int divisor)
void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count)
void rlDrawVertexArray(int offset, int count)
void rlDrawVertexArrayElements(int offset, int count, const void *buffer)
void rlDrawVertexArrayInstanced(int offset, int count, int instances)
void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances)
unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount)
unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
unsigned int rlLoadTextureCubemap(void *data, int size, int format)
unsigned int rlLoadTextureCubemap(const void *data, int size, int format)
void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data)
void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType)
void rlGetGlTextureFormats(int format, int *glInternalFormat, int *glFormat, int *glType)
const char *rlGetPixelFormatName(unsigned int format)
void rlUnloadTexture(unsigned int id)
void rlGenerateMipmaps(Texture2D *texture)
void *rlReadTexturePixels(Texture2D texture)
void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps)
void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
unsigned char *rlReadScreenPixels(int width, int height)
unsigned int rlLoadFramebuffer(int width, int height)
void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType)
void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel)
bool rlFramebufferComplete(unsigned int id)
void rlUnloadFramebuffer(unsigned int id)
void rlLoadMesh(Mesh *mesh, bool dynamic)
void rlUpdateMesh(Mesh mesh, int buffer, int num)
void rlUpdateMeshAt(Mesh mesh, int buffer, int num, int index)
void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int count)
void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
void rlUnloadMesh(Mesh mesh)
unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode)
unsigned int rlCompileShader(const char *shaderCode, int type)
unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
void rlUnloadShaderProgram(unsigned int id)
int rlGetLocationUniform(unsigned int shaderId, const char *uniformName)
int rlGetLocationAttrib(unsigned int shaderId, const char *attribName)
void rlSetUniform(int locIndex, const void *value, int uniformType, int count)
void rlSetUniformMatrix(int locIndex, Matrix mat)
void rlSetUniformSampler(int locIndex, unsigned int textureId)
void rlSetShader(unsigned int id, int *locs)
#if defined(GRAPHICS_API_OPENGL_43)
unsigned int rlLoadComputeShaderProgram(int shaderId)
void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ)
unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint)
void rlUnloadShaderBuffer(unsigned int ssboId)
void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned long long dataSize, unsigned long long offset)
unsigned long long rlGetShaderBufferSize(unsigned int id)
void rlReadShaderBufferElements(unsigned int id, void *dest, unsigned long long count, unsigned long long offset)
void rlBindShaderBuffer(unsigned int id, unsigned int index)
void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned long long destOffset, unsigned long long srcOffset, unsigned long long count)
void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly)
#endif
Matrix rlGetMatrixModelview(void)
Matrix rlGetMatrixProjection(void)
Matrix rlGetMatrixTransform(void)
Matrix rlGetMatrixProjectionStereo(int eye)
Matrix rlGetMatrixViewOffsetStereo(int eye)
void rlSetMatrixProjection(Matrix proj)
void rlSetMatrixModelview(Matrix view)
void rlSetMatrixProjectionStereo(Matrix right, Matrix left)
void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left)
void rlLoadDrawCube(void)
void rlLoadDrawQuad(void)