Add raygui #13
7 changed files with 2006 additions and 219 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -4,3 +4,6 @@
|
|||
[submodule "submodules/raylib"]
|
||||
path = submodules/raylib
|
||||
url = https://github.com/raysan5/raylib.git
|
||||
[submodule "submodules/raygui"]
|
||||
path = submodules/raygui
|
||||
url = https://github.com/raysan5/raygui.git
|
||||
|
|
|
|||
216
Makefile
216
Makefile
|
|
@ -1,17 +1,14 @@
|
|||
# hate-no-d
|
||||
#
|
||||
# Native platforms are auto-detected from uname. Cross targets are explicit:
|
||||
# Platforms are auto-detected from uname; cross targets are explicit:
|
||||
# make
|
||||
# make PLATFORM=Android ANDROID_NDK=/opt/android-ndk [ANDROID_ABI=... ANDROID_API=...]
|
||||
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
|
||||
#
|
||||
# Targets:
|
||||
# make the CLI (hate-no-d or hate-no-d.exe)
|
||||
# make PLATFORM=Android ANDROID_NDK=/opt/ndk [ANDROID_ABI=... ANDROID_API=...]
|
||||
# make help every target and option
|
||||
#
|
||||
# raylib is linked into the CLI. Objects, rlparser and its generated API tables
|
||||
# go to build/; only the CLI and hate-no-d.lua land in the repository root.
|
||||
# raylib and LuaJIT build in their own trees (both gitignore their output).
|
||||
# LuaJIT and raylib build inside their own submodule trees. Objects, rlparser
|
||||
# and its API tables go to build/; only the CLI and the generated hate-no-d.lua
|
||||
# land in the repository root.
|
||||
|
||||
# luajit requires GNU Make. BSD make fails on .FEATURES before this guard.
|
||||
ifndef .FEATURES
|
||||
|
|
@ -20,33 +17,46 @@ endif
|
|||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Paths and outputs
|
||||
# ---------------------------------------------------------------------------
|
||||
LUAJIT_DIR := submodules/luajit
|
||||
LUAJIT_SRC := $(LUAJIT_DIR)/src
|
||||
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
|
||||
|
||||
RAYLIB_DIR := submodules/raylib
|
||||
RAYLIB_SRC := $(RAYLIB_DIR)/src
|
||||
RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a
|
||||
RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser
|
||||
|
||||
RAYGUI_DIR := submodules/raygui
|
||||
RAYGUI_SRC := $(RAYGUI_DIR)/src
|
||||
|
||||
BUILD_DIR := build
|
||||
API_DIR := $(BUILD_DIR)/api
|
||||
RLPARSER := $(BUILD_DIR)/rlparser
|
||||
RAYLIB_API := $(API_DIR)/raylib_api.lua
|
||||
BINDING := hate-no-d.lua
|
||||
OBJ := $(BUILD_DIR)/hate-no-d.o
|
||||
|
||||
RAYLIB_API := $(API_DIR)/raylib_api.lua
|
||||
RLGL_API := $(API_DIR)/rlgl_api.lua
|
||||
RAYMATH_API := $(API_DIR)/raymath_api.lua
|
||||
RAYGUI_API := $(API_DIR)/raygui_api.lua
|
||||
|
||||
BINDING := hate-no-d.lua
|
||||
BIN := hate-no-d
|
||||
|
||||
GEN_FLAGS := --raylib=$(API_DIR)/raylib_api.lua \
|
||||
--rlgl=$(API_DIR)/rlgl_api.lua \
|
||||
--raymath=$(API_DIR)/raymath_api.lua
|
||||
|
||||
# Archiver passed to raylib's build. Cross toolchains ship their own.
|
||||
AR ?= ar
|
||||
# ---------------------------------------------------------------------------
|
||||
# Platform detection
|
||||
# ---------------------------------------------------------------------------
|
||||
# PLATFORM= always wins over uname.
|
||||
PLATFORM ?= $(shell uname -s)
|
||||
|
||||
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
||||
LUAJIT_EXTRA :=
|
||||
|
||||
# Platform detection. PLATFORM= always wins over uname.
|
||||
PLATFORM ?= $(shell uname -s)
|
||||
# raylib build args; per-platform blocks below override them.
|
||||
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC
|
||||
RAYLIB_LINK := -Wl,--whole-archive $(RAYLIB_AR) -Wl,--no-whole-archive
|
||||
|
||||
ifeq ($(PLATFORM),Linux)
|
||||
OS_KIND := linux
|
||||
|
|
@ -72,10 +82,6 @@ else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly))
|
|||
OS_KIND := bsd
|
||||
endif
|
||||
|
||||
# raylib build args; per-platform overrides follow.
|
||||
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC
|
||||
RAYLIB_LINK := -Wl,--whole-archive $(RAYLIB_AR) -Wl,--no-whole-archive
|
||||
|
||||
# Linux (ELF)
|
||||
ifeq ($(OS_KIND),linux)
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
|
|
@ -83,15 +89,12 @@ ifeq ($(OS_KIND),linux)
|
|||
LINK_TARGET := $(BIN)
|
||||
endif
|
||||
|
||||
# BSD (ELF, dlopen lives in libc)
|
||||
# BSD (ELF, dlopen lives in libc). ld searches /usr/lib only, while pkg(8)
|
||||
# installs into /usr/local, pkgsrc into /usr/pkg and base X11 into /usr/X11R6
|
||||
# or /usr/X11R7, so every -l below needs an explicit -L. raylib's own BSD link
|
||||
# list also omits the X11 set.
|
||||
ifeq ($(OS_KIND),bsd)
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
# ld searches /usr/lib only. pkg(8) installs into /usr/local (FreeBSD,
|
||||
# DragonFly), pkgsrc into /usr/pkg (NetBSD), and base X11 lives in
|
||||
# /usr/X11R6 (OpenBSD) or /usr/X11R7 (NetBSD), so every -l below needs an
|
||||
# explicit -L. raylib's own BSD link list omits the X11 set and these paths,
|
||||
# which is why its examples only link on a system with the libs on the
|
||||
# default search path.
|
||||
BSD_LIBDIRS := -L/usr/local/lib
|
||||
ifneq (,$(filter OpenBSD NetBSD,$(PLATFORM)))
|
||||
BSD_LIBDIRS += -L/usr/pkg/lib -L/usr/X11R6/lib -L/usr/X11R7/lib
|
||||
|
|
@ -104,8 +107,8 @@ ifeq ($(OS_KIND),bsd)
|
|||
LINK_TARGET := $(BIN)
|
||||
endif
|
||||
|
||||
# Windows (PE, cross-compiled from a POSIX host with mingw-w64; native builds use
|
||||
# build.bat). i686 needs a 32-bit host compiler, since LuaJIT's buildvm runs
|
||||
# Windows (PE), cross-compiled from a POSIX host with mingw-w64; native builds
|
||||
# use build.bat. i686 needs a 32-bit host compiler, since LuaJIT's buildvm runs
|
||||
# natively and must match the target pointer size:
|
||||
# make PLATFORM=Windows WIN_ARCH=i686 HOST_CC="gcc -m32"
|
||||
ifeq ($(OS_KIND),windows)
|
||||
|
|
@ -158,10 +161,9 @@ ifeq ($(OS_KIND),macos)
|
|||
endif
|
||||
endif
|
||||
|
||||
# Android (ELF, cross-compiled with the NDK)
|
||||
#
|
||||
# 64-bit ABIs build on any 64-bit host. armeabi-v7a additionally needs a
|
||||
# 32-bit host compiler: make ... HOST_CC="gcc -m32"
|
||||
# Android (ELF), cross-compiled with the NDK. 64-bit ABIs build on any 64-bit
|
||||
# host; armeabi-v7a also needs a 32-bit host compiler:
|
||||
# make PLATFORM=Android ANDROID_NDK=... HOST_CC="gcc -m32"
|
||||
ifeq ($(OS_KIND),android)
|
||||
ANDROID_NDK ?= $(ANDROID_NDK_HOME)
|
||||
ANDROID_API ?= 21
|
||||
|
|
@ -226,30 +228,107 @@ ifndef LINK_TARGET
|
|||
$(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD)
|
||||
endif
|
||||
|
||||
# Host compiler for build-time tools (rlparser); the Windows branch pins gcc.
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tools and flags
|
||||
# ---------------------------------------------------------------------------
|
||||
# Host compiler for build-time tools (rlparser, LuaJIT's minilua/buildvm).
|
||||
HOST_CC ?= cc
|
||||
# Host LuaJIT that runs the binding generator.
|
||||
LUAJIT ?= luajit
|
||||
# Archiver passed to raylib's build. Cross toolchains ship their own.
|
||||
AR ?= ar
|
||||
|
||||
# raylib's RELEASE build appends -O1; -O2 is a big win for CPU-bound code.
|
||||
# Changing it needs `make clean` -- objects are not flag-aware.
|
||||
RAYLIB_OPT ?= -O2
|
||||
RAYLIB_MAKE_ARGS += CUSTOM_CFLAGS="$(RAYLIB_OPT)"
|
||||
|
||||
# Compiler / linker flags
|
||||
CFLAGS ?= -O2 -Wall
|
||||
CPPFLAGS += -I$(LUAJIT_SRC)
|
||||
|
||||
# LuaJIT: static archive only, built through the upstream GNU Makefile.
|
||||
# raygui.h includes raylib.h, hence both include paths. raymath needs no header
|
||||
# here: rcore.c already compiled it into libraylib.a. raygui has no such owner,
|
||||
# so its implementation is force-included into the CLI's translation unit.
|
||||
CPPFLAGS += -I$(LUAJIT_SRC) -I$(RAYLIB_SRC) -I$(RAYGUI_SRC) \
|
||||
-DRAYGUI_IMPLEMENTATION -include $(RAYGUI_SRC)/raygui.h
|
||||
|
||||
LUAJIT_MAKE_ARGS := BUILDMODE=static XCFLAGS="$(LUAJIT_XCFLAGS)" $(LUAJIT_EXTRA)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Submodules (static archives only)
|
||||
# ---------------------------------------------------------------------------
|
||||
$(LUAJIT_AR):
|
||||
$(MAKE) -C $(LUAJIT_SRC) $(LUAJIT_MAKE_ARGS) "LJCORE_O=ljamalg.o" libluajit.a
|
||||
|
||||
# raylib: static archive only; CC/AR are pinned, its Makefile defaults to host gcc/ar.
|
||||
# CC/AR are pinned: raylib's Makefile would otherwise pick host defaults.
|
||||
$(RAYLIB_AR):
|
||||
$(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)"
|
||||
|
||||
# Targets
|
||||
# ---------------------------------------------------------------------------
|
||||
# CLI
|
||||
# ---------------------------------------------------------------------------
|
||||
all: $(LINK_TARGET) $(BINDING)
|
||||
|
||||
$(BUILD_DIR):
|
||||
@mkdir -p $@
|
||||
|
||||
$(API_DIR): | $(BUILD_DIR)
|
||||
@mkdir -p $@
|
||||
|
||||
$(OBJ): hate-no-d.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
||||
|
||||
# raylib is pulled in whole: nothing references it, so the linker would drop it
|
||||
# and ffi.C would have nothing to resolve.
|
||||
$(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
||||
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lua bindings (hate-no-d.lua)
|
||||
#
|
||||
# gen-hate-no-d.lua turns the rlparser tables for raylib.h, rlgl.h, raymath.h
|
||||
# and raygui.h into one ffi.cdef block plus constants, wrappers and LuaCATS
|
||||
# comments.
|
||||
#
|
||||
# The tables are generated into build/api from the pinned submodule headers, so
|
||||
# raylib's tools/rlparser/output (where raylib_api.lua is tracked) stays clean.
|
||||
# rlparser runs on HOST_CC, never the target CC: cross builds still produce the
|
||||
# same platform-independent binding. The script has these paths baked in
|
||||
# (build/api/*.lua in, hate-no-d.lua out), so BINDING must match OUT.
|
||||
# ---------------------------------------------------------------------------
|
||||
$(RLPARSER): $(RLPARSER_DIR)/rlparser.c | $(BUILD_DIR)
|
||||
$(HOST_CC) -O2 -Wall -std=c99 -o $@ $(RLPARSER_DIR)/rlparser.c
|
||||
|
||||
$(RAYLIB_API): $(RLPARSER) $(RAYLIB_SRC)/raylib.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raylib.h -o $@ -f LUA -d RLAPI
|
||||
|
||||
$(RLGL_API): $(RLPARSER) $(RAYLIB_SRC)/rlgl.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/rlgl.h -o $@ -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
||||
|
||||
$(RAYMATH_API): $(RLPARSER) $(RAYLIB_SRC)/raymath.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
|
||||
|
||||
$(RAYGUI_API): $(RLPARSER) $(RAYGUI_SRC)/raygui.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYGUI_SRC)/raygui.h -o $@ -f LUA -d RAYGUIAPI
|
||||
|
||||
$(BINDING): gen-hate-no-d.lua $(RLGL_API) $(RAYMATH_API) $(RAYLIB_API) $(RAYGUI_API)
|
||||
@command -v $(LUAJIT) >/dev/null 2>&1 || { \
|
||||
echo "hate-no-d: cannot run '$(LUAJIT)' -- install LuaJIT or set LUAJIT=..." >&2; exit 1; }
|
||||
$(LUAJIT) gen-hate-no-d.lua
|
||||
|
||||
bindings: $(BINDING)
|
||||
|
||||
# Fail if regeneration is not byte-identical or the module does not load.
|
||||
check-bindings: $(BINDING)
|
||||
@before=$$(cksum $(BINDING)); \
|
||||
$(LUAJIT) gen-hate-no-d.lua; \
|
||||
[ "$$before" = "$$(cksum $(BINDING))" ] || { \
|
||||
echo "hate-no-d.lua: regeneration is not byte-identical" >&2; exit 1; }
|
||||
$(LUAJIT) -e 'local M = dofile("$(BINDING)"); assert(type(M) == "table"); assert(type(M.GetMousePosition) == "function", "raylib"); assert(type(M.rlLoadIdentity) == "function", "rlgl"); assert(type(M.Vector2Add) == "function", "raymath"); assert(type(M.GuiButton) == "function", "raygui"); print("bindings ok")'
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Info and maintenance
|
||||
# ---------------------------------------------------------------------------
|
||||
help:
|
||||
@echo "hate-no-d -- LuaJIT-based Lua runtime"
|
||||
@echo ""
|
||||
|
|
@ -278,60 +357,6 @@ help:
|
|||
@echo " LDFLAGS= extra linker flags"
|
||||
@echo " AR= archiver for raylib's build"
|
||||
|
||||
all: $(LINK_TARGET) $(BINDING)
|
||||
|
||||
$(BUILD_DIR):
|
||||
@mkdir -p $@
|
||||
|
||||
$(API_DIR): | $(BUILD_DIR)
|
||||
@mkdir -p $@
|
||||
|
||||
$(OBJ): hate-no-d.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
||||
|
||||
# raylib is pulled in whole: nothing references it, so the linker would drop it
|
||||
# and ffi.C would have nothing to resolve.
|
||||
$(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
||||
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lua bindings (hate-no-d.lua)
|
||||
#
|
||||
# gen-hate-no-d.lua turns the rlparser tables for raylib.h, rlgl.h and raymath.h
|
||||
# into one ffi.cdef block plus constants, wrappers and LuaCATS comments.
|
||||
#
|
||||
# The tables are generated into build/api from the pinned submodule headers, so
|
||||
# raylib's tools/rlparser/output (where raylib_api.lua is tracked) stays clean.
|
||||
# rlparser itself is built with HOST_CC, never the target CC: cross builds still
|
||||
# run it to produce the platform-independent binding.
|
||||
# ---------------------------------------------------------------------------
|
||||
$(RLPARSER): $(RLPARSER_DIR)/rlparser.c | $(BUILD_DIR)
|
||||
$(HOST_CC) -O2 -Wall -std=c99 -o $@ $(RLPARSER_DIR)/rlparser.c
|
||||
|
||||
$(RAYLIB_API): $(RLPARSER) $(RAYLIB_SRC)/raylib.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raylib.h -o $@ -f LUA -d RLAPI
|
||||
|
||||
$(API_DIR)/rlgl_api.lua: $(RLPARSER) $(RAYLIB_SRC)/rlgl.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/rlgl.h -o $@ -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
||||
|
||||
$(API_DIR)/raymath_api.lua: $(RLPARSER) $(RAYLIB_SRC)/raymath.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
|
||||
|
||||
$(BINDING): gen-hate-no-d.lua $(API_DIR)/rlgl_api.lua $(API_DIR)/raymath_api.lua $(RAYLIB_API)
|
||||
@command -v $(LUAJIT) >/dev/null 2>&1 || { \
|
||||
echo "hate-no-d: cannot run '$(LUAJIT)' -- install LuaJIT or set LUAJIT=..." >&2; exit 1; }
|
||||
$(LUAJIT) gen-hate-no-d.lua --out=$@ $(GEN_FLAGS)
|
||||
|
||||
bindings: $(BINDING)
|
||||
|
||||
# Fail if regeneration is not byte-identical or the module does not load.
|
||||
check-bindings: $(BINDING)
|
||||
$(LUAJIT) gen-hate-no-d.lua --out=$(BUILD_DIR)/hate-no-d.lua.tmp $(GEN_FLAGS)
|
||||
cmp $(BINDING) $(BUILD_DIR)/hate-no-d.lua.tmp
|
||||
rm -f $(BUILD_DIR)/hate-no-d.lua.tmp
|
||||
$(LUAJIT) -e 'local M = dofile("$(BINDING)"); assert(type(M) == "table"); assert(type(M.GetMousePosition) == "function", "raylib"); assert(type(M.rlLoadIdentity) == "function", "rlgl"); assert(type(M.Vector2Add) == "function", "raymath"); print("bindings ok")'
|
||||
|
||||
# Resolved configuration for the current target; useful before a cross build.
|
||||
print-config:
|
||||
@echo "PLATFORM = $(PLATFORM)"
|
||||
|
|
@ -364,6 +389,5 @@ clean:
|
|||
rm -rf $(BUILD_DIR)
|
||||
rm -f $(BIN) hate-no-d.exe libhate-no-d.a libhate-no-d.a.mri $(LUAJIT_AR) $(RAYLIB_AR)
|
||||
rm -f $(BINDING)
|
||||
rm -f hate-no-d.o # object from builds that predate the move into build/
|
||||
|
||||
.PHONY: all clean print-config help bindings check-bindings
|
||||
|
|
|
|||
11
build.bat
11
build.bat
|
|
@ -109,7 +109,10 @@ echo === Building hate-no-d.exe ===
|
|||
if not exist "build" mkdir "build"
|
||||
if exist "build\hate-no-d.obj" del /q "build\hate-no-d.obj"
|
||||
cl /nologo /c /O2 /W4 /MT /D_CRT_SECURE_NO_WARNINGS ^
|
||||
/I "submodules\luajit\src" /Fo"build\hate-no-d.obj" hate-no-d.c
|
||||
/I "submodules\luajit\src" /I "submodules\raylib\src" /I "submodules\raygui\src" ^
|
||||
/DRAYGUI_IMPLEMENTATION /FI"submodules\raygui\src\raygui.h" ^
|
||||
/D"RAYGUIAPI=__declspec(dllexport)" ^
|
||||
/Fo"build\hate-no-d.obj" hate-no-d.c
|
||||
if errorlevel 1 goto :fail
|
||||
|
||||
link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
|
||||
|
|
@ -118,10 +121,10 @@ link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
|
|||
opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib
|
||||
if errorlevel 1 goto :fail
|
||||
|
||||
@rem ffi.C reads the exe's export table, so verify raylib really got exported.
|
||||
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" >nul
|
||||
@rem ffi.C reads the exe's export table, so verify raylib and raygui really got exported.
|
||||
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" /C:"GuiButton" >nul
|
||||
if errorlevel 1 (
|
||||
echo build.bat: hate-no-d.exe does not export raylib - ffi.C would not find it.
|
||||
echo build.bat: hate-no-d.exe does not export raylib/raygui - ffi.C would not find it.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1,5 @@
|
|||
-I./submodules/luajit/src
|
||||
-I./submodules/raylib/src
|
||||
-I./submodules/raygui/src
|
||||
-DRAYGUI_IMPLEMENTATION
|
||||
-include ./submodules/raygui/src/raygui.h
|
||||
|
|
|
|||
|
|
@ -20,85 +20,41 @@ build never writes into raylib's tools/ tree:
|
|||
-o build/api/rlgl_api.lua -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
||||
build/rlparser -i submodules/raylib/src/raymath.h \
|
||||
-o build/api/raymath_api.lua -f LUA -d RMAPI
|
||||
build/rlparser -i submodules/raygui/src/raygui.h \
|
||||
-o build/api/raygui_api.lua -f LUA -d RAYGUIAPI
|
||||
|
||||
Usage:
|
||||
luajit gen-hate-no-d.lua [--out=hate-no-d.lua] [--no-rlgl] [--no-raymath]
|
||||
[--raylib=path] [--rlgl=path] [--raymath=path]
|
||||
Run from the repository root; every table above is required and the result is
|
||||
always written to hate-no-d.lua.
|
||||
|
||||
raymath needs no extra translation unit: raylib's own rcore.c defines
|
||||
RAYMATH_IMPLEMENTATION before including raymath.h, so libraylib.a already
|
||||
contains all 146 raymath symbols (verified with nm). Linking the library
|
||||
with --whole-archive exposes them to ffi.C.
|
||||
|
||||
raygui is header-only, its implementation is force-included into the CLI's
|
||||
translation unit (-DRAYGUI_IMPLEMENTATION -include .../raygui.h), so its
|
||||
symbols land in the executable and --whole-archive is not involved.
|
||||
]]
|
||||
|
||||
local CFG = {
|
||||
raylib = "build/api/raylib_api.lua",
|
||||
rlgl = "build/api/rlgl_api.lua",
|
||||
raymath = "build/api/raymath_api.lua",
|
||||
out = "hate-no-d.lua",
|
||||
use_rlgl = true,
|
||||
use_raymath = true,
|
||||
}
|
||||
|
||||
local USAGE = [[
|
||||
usage: luajit gen-hate-no-d.lua [options]
|
||||
|
||||
--out=PATH output file (default: hate-no-d.lua)
|
||||
--raylib=PATH raylib parser table (default: build/api/raylib_api.lua)
|
||||
--rlgl=PATH rlgl parser table (default: build/api/rlgl_api.lua)
|
||||
--raymath=PATH raymath parser table(default: build/api/raymath_api.lua)
|
||||
--no-rlgl skip rlgl
|
||||
--no-raymath skip raymath
|
||||
-h, --help this text
|
||||
]]
|
||||
local RAYLIB_API = "build/api/raylib_api.lua"
|
||||
local RLGL_API = "build/api/rlgl_api.lua"
|
||||
local RAYMATH_API = "build/api/raymath_api.lua"
|
||||
local RAYGUI_API = "build/api/raygui_api.lua"
|
||||
local OUT = "hate-no-d.lua"
|
||||
|
||||
local function die(fmt, ...)
|
||||
io.stderr:write("gen-hate-no-d: " .. string.format(fmt, ...) .. "\n")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local function warn(fmt, ...)
|
||||
io.stderr:write("gen-hate-no-d: warning: " .. string.format(fmt, ...) .. "\n")
|
||||
end
|
||||
|
||||
for i = 1, #arg do
|
||||
local a = arg[i]
|
||||
local key, value = a:match("^%-%-([%w]+)=(.*)$")
|
||||
if key == "out" then
|
||||
CFG.out = value
|
||||
elseif key == "raylib" then
|
||||
CFG.raylib = value
|
||||
elseif key == "rlgl" then
|
||||
CFG.rlgl = value
|
||||
elseif key == "raymath" then
|
||||
CFG.raymath = value
|
||||
elseif key then
|
||||
die("unknown option --%s", key)
|
||||
elseif a == "--no-rlgl" then
|
||||
CFG.use_rlgl = false
|
||||
elseif a == "--no-raymath" then
|
||||
CFG.use_raymath = false
|
||||
elseif a == "-h" or a == "--help" then
|
||||
io.write(USAGE)
|
||||
os.exit(0)
|
||||
else
|
||||
die("unknown argument %s", a)
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- loading
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
local function load_api(path, optional)
|
||||
local function load_api(path)
|
||||
local chunk, err = loadfile(path)
|
||||
if not chunk then
|
||||
if optional then
|
||||
warn("skipping %s (%s)", path, err)
|
||||
return nil
|
||||
end
|
||||
die("cannot load %s: %s", path, err)
|
||||
return nil
|
||||
end
|
||||
local ok, data = pcall(chunk)
|
||||
if not ok then
|
||||
|
|
@ -110,28 +66,17 @@ local function load_api(path, optional)
|
|||
return data
|
||||
end
|
||||
|
||||
local apis = {}
|
||||
local raylib_api = load_api(RAYLIB_API)
|
||||
local raygui_api = load_api(RAYGUI_API)
|
||||
|
||||
local raylib_api = load_api(CFG.raylib)
|
||||
apis[#apis + 1] = { tag = "raylib", data = raylib_api }
|
||||
|
||||
if CFG.use_rlgl then
|
||||
local data = load_api(CFG.rlgl, false)
|
||||
if data then
|
||||
apis[#apis + 1] = { tag = "rlgl", data = data }
|
||||
else
|
||||
warn("rlgl API table missing, building raylib.h only")
|
||||
end
|
||||
end
|
||||
|
||||
if CFG.use_raymath then
|
||||
local data = load_api(CFG.raymath, false)
|
||||
if data then
|
||||
apis[#apis + 1] = { tag = "raymath", data = data }
|
||||
else
|
||||
warn("raymath API table missing, building without raymath")
|
||||
end
|
||||
end
|
||||
-- Merge order matters: raylib defines the base types (Texture, ...) that raygui
|
||||
-- redeclares in its standalone fallback, so raylib always goes first.
|
||||
local apis = {
|
||||
raylib_api,
|
||||
load_api(RLGL_API),
|
||||
load_api(RAYMATH_API),
|
||||
raygui_api,
|
||||
}
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- type model
|
||||
|
|
@ -206,18 +151,7 @@ local function sanitize_fields(fields)
|
|||
return clean
|
||||
end
|
||||
|
||||
local function add_api(tag)
|
||||
local data
|
||||
for _, item in ipairs(apis) do
|
||||
if item.tag == tag then
|
||||
data = item.data
|
||||
break
|
||||
end
|
||||
end
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
local function add_api(data)
|
||||
for _, s in ipairs(data.structs or {}) do
|
||||
if not STRUCTS[s.name] and not ALIASES[s.name] then
|
||||
STRUCTS[s.name] = {
|
||||
|
|
@ -250,13 +184,12 @@ local function add_api(tag)
|
|||
end
|
||||
|
||||
for _, f in ipairs(data.functions or {}) do
|
||||
f._tag = tag
|
||||
FUNCS[#FUNCS + 1] = f
|
||||
end
|
||||
end
|
||||
|
||||
for _, item in ipairs(apis) do
|
||||
add_api(item.tag)
|
||||
for _, data in ipairs(apis) do
|
||||
add_api(data)
|
||||
end
|
||||
|
||||
-- TraceLogCallback carries va_list, which LuaJIT cannot pass to a Lua
|
||||
|
|
@ -677,14 +610,16 @@ local function find_define(data, name)
|
|||
end
|
||||
|
||||
version = tostring(find_define(raylib_api, "RAYLIB_VERSION") or "unknown")
|
||||
local raygui_version = tostring(find_define(raygui_api, "RAYGUI_VERSION") or "unknown")
|
||||
|
||||
w("--[[")
|
||||
w(" hate-no-d.lua - generated by gen-hate-no-d.lua, do not edit.")
|
||||
w("")
|
||||
w(" raylib " .. version .. " / rlgl / raymath")
|
||||
w(" raylib " .. version .. " / rlgl / raymath / raygui " .. raygui_version)
|
||||
w(" Functions: " .. tostring(#FUNCS))
|
||||
w("")
|
||||
w(" raymath symbols come from rcore.o (RAYMATH_IMPLEMENTATION) in libraylib.a.")
|
||||
w(" raygui symbols come from a forced -include of raygui.h (RAYGUI_IMPLEMENTATION).")
|
||||
w("]]")
|
||||
w("")
|
||||
w('local ffi = require("ffi")')
|
||||
|
|
@ -803,8 +738,8 @@ w("")
|
|||
local enum_constants = {}
|
||||
local seen_const = {}
|
||||
|
||||
for _, item in ipairs(apis) do
|
||||
for _, enum in ipairs(item.data.enums or {}) do
|
||||
for _, data in ipairs(apis) do
|
||||
for _, enum in ipairs(data.enums or {}) do
|
||||
w("---@enum raylib." .. enum.name)
|
||||
w("M." .. enum.name .. " = {")
|
||||
for _, v in ipairs(enum.values or {}) do
|
||||
|
|
@ -825,8 +760,8 @@ for _, item in ipairs(apis) do
|
|||
end
|
||||
end
|
||||
|
||||
for _, item in ipairs(apis) do
|
||||
for _, enum in ipairs(item.data.enums or {}) do
|
||||
for _, data in ipairs(apis) do
|
||||
for _, enum in ipairs(data.enums or {}) do
|
||||
for _, v in ipairs(enum.values or {}) do
|
||||
w("---@type raylib." .. enum.name)
|
||||
w("M." .. v.name .. " = M." .. enum.name .. "." .. v.name)
|
||||
|
|
@ -852,8 +787,8 @@ local function eval_float_math(expr)
|
|||
return value
|
||||
end
|
||||
|
||||
for _, item in ipairs(apis) do
|
||||
for _, d in ipairs(item.data.defines or {}) do
|
||||
for _, data in ipairs(apis) do
|
||||
for _, d in ipairs(data.defines or {}) do
|
||||
if not seen_const[d.name] then
|
||||
local dtype = d.type
|
||||
local emitted = false
|
||||
|
|
@ -1166,10 +1101,9 @@ w("return M")
|
|||
----------------------------------------------------------------------------
|
||||
|
||||
local text = table.concat(out, "\n") .. "\n"
|
||||
local file, err = io.open(CFG.out, "wb")
|
||||
local file, err = io.open(OUT, "wb")
|
||||
if not file then
|
||||
die("cannot write %s: %s", CFG.out, err)
|
||||
return
|
||||
die("cannot write %s: %s", OUT, err)
|
||||
end
|
||||
file:write(text)
|
||||
file:close()
|
||||
|
|
@ -1187,4 +1121,4 @@ for _ in pairs(CALLBACKS) do
|
|||
end
|
||||
io.stderr:write(string.format(
|
||||
"gen-hate-no-d: wrote %s (%d functions, %d structs, %d aliases, %d callbacks, %d lines)\n",
|
||||
CFG.out, emitted_wrappers, n_struct, n_alias, n_cb, #out))
|
||||
OUT, emitted_wrappers, n_struct, n_alias, n_cb, #out))
|
||||
|
|
|
|||
1822
hate-no-d.lua
1822
hate-no-d.lua
File diff suppressed because it is too large
Load diff
1
submodules/raygui
Submodule
1
submodules/raygui
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1abccb3a5303d041dc14404b7dd874fa665dd4af
|
||||
Loading…
Reference in a new issue