# hate-no-d A [Love2D](https://www.love2d.org/) antagonist. A glorified [Makefile](./Makefile). Should work on: - Linux (x86, x86_64, ARM, ARM64) - Android (armeabi-v7a, arm64-v8a, x86, x86_64) - macOS (x86_64, ARM64) - Windows (x86, x86_64 via MinGW; ARM64 via MSVC) - FreeBSD, OpenBSD, NetBSD (x86, x86_64) or DragonFly BSD (x86_64) ## Quick Start Save this as `quick-start.lua`: ```lua local hnd = require("hate-no-d") hnd.InitWindow(1280, 720, "hate-no-d") hnd.SetTargetFPS(60) local text = "Your first hate-no-d application!" local fontSize = 48 while not hnd.WindowShouldClose() do hnd.BeginDrawing() hnd.ClearBackground(hnd.SKYBLUE) local width = hnd.MeasureText(text, fontSize) hnd.DrawText(text, (hnd.GetScreenWidth() - width)/2, (hnd.GetScreenHeight() - fontSize)/2, fontSize, hnd.DARKBLUE) hnd.EndDrawing() end hnd.CloseWindow() ``` Run it: ```sh ./hate-no-d quick-start.lua ``` On Windows: ```bat hate-no-d.exe quick-start.lua ``` `hate-no-d.lua` is the generated raylib/rlgl/raymath binding; release archives ship it next to the binary. ## Resource ownership Every `Load*`/`Gen*` result that raylib hands to the caller is owned by the Lua value you get back. hate-no-d attaches a finalizer to the underlying cdata, so dropping the last reference is enough: ```lua local tex = hnd.LoadTexture("sprite.png") -- armed tex = nil collectgarbage() -- raylib UnloadTexture() runs here ``` This covers textures, render textures, shaders, meshes, models, materials, fonts, waves, sounds, music streams, audio streams, images, automation event lists, directory listings, VR stereo configs, and the raw-pointer loaders (`LoadImageColors`, `LoadImagePalette`, `LoadFontData`, `LoadMaterials`, `LoadModelAnimations`, `LoadRandomSequence`, `LoadWaveSamples`, `LoadCodepoints`, `LoadTextLines`, `LoadFileData`, `CompressData`, `DecompressData`, `DecodeDataBase64`, `ExportImageToMemory`, `MemAlloc`, and rlgl's pixel readers). - **Readiness gates.** A finalizer never touches a dead subsystem. GPU releases only run while a window is alive, audio releases only while the audio device is alive, and anything still armed when a window is closed or recreated is skipped rather than freed. `InitWindow`/`CloseWindow` bump an internal GPU generation so stale handles are never unloaded against a new context. - **`Unload*` is explicit and idempotent.** `hnd.UnloadImage(img)` frees immediately, zeroes the struct, and is safe to call again. It also cancels the finalizer, so a resource is never released twice. `M._ownership` exposes `armed`/`released`/`skipped`/`errors` counters (mostly useful for tests). - **Array loaders return their count.** Functions that fill a C `int *` count out-parameter (`LoadImagePalette`, `LoadFontData`, `LoadMaterials`, `LoadModelAnimations`, `LoadTextLines`, `LoadFileData`, `CompressData`, `DecompressData`, `DecodeDataBase64`, `ExportImageToMemory`) now return `pointer, count`. Passing a cdata still fills it, so existing code keeps working; the extra return value is safe to ignore. - **Views are never freed.** Values that alias raylib-owned memory are plain copies: `font.texture`, `rt.texture`, `rt.depth`, `model.meshes[i]`, `model.materials[i]`, `GetGlyphInfo()`, `GetFontDefault()`, `GetShapesTexture()`, and `LoadDroppedFiles()`. Keep the owner alive while you use a view — `GetGlyphInfo()`'s `image.data` points into the font. - **Materials are special.** `UnloadMaterial`/the material finalizer free only the `maps` array, never the shader or textures it references (those may be shared). Textures assigned with `SetMaterialTexture` are pinned for the lifetime of the material; `SetShapesTexture` pins the shapes texture, and unloading that texture restores the previous one. - **Mesh ownership transfers.** `LoadModelFromMesh(mesh)` consumes the mesh — the model frees it. Calling `UnloadMesh` on the consumed handle is a no-op. `LoadSoundAlias(src)` keeps `src` alive until the alias is released, and `LoadMusicStreamFromMemory` keeps its buffer alive. - **Raw memory.** `MemAlloc`/`MemRealloc` results are GC-managed; `MemFree` cancels the finalizer before freeing, so explicit frees are safe. `M.C` is the raw `ffi` namespace: calls made through it are unmanaged. - **Process exit.** The CLI runs finalizers on normal exit (it calls `lua_close`). `os.exit()` skips them; use `os.exit(code, true)` if you need them to run. The ownership classification is exhaustive: the generator refuses to emit a binding if any function's return shape is unclassified, and `make check-bindings` diffs `ownership.txt` against the current raylib API. `make check` runs the test suite (including a valgrind pass over the RAM-only cases). ## Building Precompiled builds can be found on the [releases page](https://git.pbento.pt/pedro-bento/hate-no-d/releases). ### Linux prerequisites Install a C toolchain, `git`, LuaJIT and the OpenGL/X11 headers. Debian/Ubuntu: ```sh sudo apt install build-essential git luajit libgl1-mesa-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev ``` Fedora: ```sh sudo dnf install gcc make git luajit mesa-libGL-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel ``` Arch: ```sh sudo pacman -S --needed base-devel git luajit mesa libx11 libxrandr libxinerama libxcursor libxi ``` Void: ```sh sudo xbps-install -S base-devel git luajit MesaLib-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel ``` Gentoo: ```sh sudo emerge --ask sys-devel/gcc dev-build/make dev-vcs/git dev-lang/luajit media-libs/mesa x11-libs/libX11 x11-libs/libXrandr x11-libs/libXinerama x11-libs/libXcursor x11-libs/libXi ``` ### macOS prerequisites ```sh xcode-select --install brew install luajit ``` The Command Line Tools provide `make` and `clang`; LuaJIT runs the binding generator. ### BSD prerequisites FreeBSD: ```sh sudo pkg install gmake luajit libX11 libXrandr libXinerama libXi libXcursor libglvnd ``` On OpenBSD, NetBSD and DragonFly install `gmake`, `luajit` (`pkg_add`, `pkgin` or `pkg`) and the X11/GL libraries if they are missing. Use `gmake` instead of `make`. ### Android prerequisites Cross-compile from Linux or macOS with the Android NDK, passed as `ANDROID_NDK` or exported as `ANDROID_NDK_HOME`. ### Windows prerequisites MSVC: install Visual Studio 2022 with the "Desktop development with C++" workload. `build.bat` finds it. raylib needs CMake 3.22+, so install CMake if the bundled copy is older. MinGW: use MSYS2 with the mingw-w64 toolchain and `make`. A native MSYS2 shell is detected automatically; cross-compiling from elsewhere needs `PLATFORM=Windows` (and `WIN_ARCH=i686` for 32-bit). ### Building from source Linux, macOS and the BSDs: ```sh git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git cd hate-no-d make ``` `make` builds the CLI and regenerates `hate-no-d.lua`, which needs a host `luajit` in `PATH` (override with `make LUAJIT=/path/to/luajit`). On the BSDs use `gmake`. Windows with MSVC: ```bat git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git cd hate-no-d build.bat ``` Android from Linux or macOS: ```sh make PLATFORM=Android ANDROID_NDK=/path/to/ndk ``` `ANDROID_ABI` defaults to `arm64-v8a` and `ANDROID_API` to `21`; `make help` lists the other ABIs. Building `armeabi-v7a` on a 64-bit host also needs `HOST_CC="gcc -m32"`.