{"id":18020920,"url":"https://github.com/edubart/nelua-decl","last_synced_at":"2025-03-26T22:30:31.926Z","repository":{"id":47413482,"uuid":"311432901","full_name":"edubart/nelua-decl","owner":"edubart","description":"C binding generator for Nelua using GCC Lua plugin.","archived":false,"fork":false,"pushed_at":"2024-01-10T23:21:15.000Z","size":1868,"stargazers_count":50,"open_issues_count":2,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-22T14:22:04.094Z","etag":null,"topics":["binder","c","gcc","lua","nelua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edubart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-09T18:42:52.000Z","updated_at":"2025-02-10T14:22:56.000Z","dependencies_parsed_at":"2024-10-30T06:28:42.343Z","dependency_job_id":null,"html_url":"https://github.com/edubart/nelua-decl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Fnelua-decl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Fnelua-decl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Fnelua-decl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Fnelua-decl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edubart","download_url":"https://codeload.github.com/edubart/nelua-decl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245747385,"owners_count":20665779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binder","c","gcc","lua","nelua"],"created_at":"2024-10-30T06:08:17.332Z","updated_at":"2025-03-26T22:30:31.219Z","avatar_url":"https://github.com/edubart.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"C binding generator for [Nelua](https://nelua.io/)\nusing [GCC Lua plugin](https://peter.colberg.org/gcc-lua).\n\nThis tool assists creating C bindings for any C library\nfor Nelua in a few steps, also enables the possibility to customize\neach library bindings via Lua scripts. Requires GCC to run.\n\n**Note: You need GCC plugin mechanism to use this (only available in Linux systems).**\n\n## Bindings example\n\nThe following cross-platform libraries bindings are ready and generated as example:\n\n* [SDL2](https://www.libsdl.org/)\n    - [sdl2.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sdl2/sdl2.nelua) (Platform window/input/graphics/audio manipulation)\n    - [sdl2_image.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sdl2/sdl2_image.nelua) (Read/write images)\n    - [sdl2_mixer.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sdl2/sdl2_mixer.nelua) (Audio mixer)\n    - [sdl2_ttf.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sdl2/sdl2_ttf.nelua) (Read TTF font files)\n* [GLFW](https://www.glfw.org/)\n    - [glfw.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/glfw/glfw.nelua) (OpenGL/Vullkan framework)\n* [minilua](https://github.com/edubart/minilua) (Lua)\n    - [lua.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/minilua/minilua.nelua) (Lua scripting language)\n* [miniminiz](https://github.com/edubart/miniminiz) (MiniZ)\n    - [miniminiz.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/miniminiz/miniminiz.nelua) (Lossless, high performance data compression library)\n* [minicoro](https://github.com/edubart/minicoro)\n    - [minicoro.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/minicoro/minicoro.nelua) (Coroutine library)\n* [miniaudio](https://miniaud.io/)\n    - [miniaudio.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/miniaudio/miniaudio.nelua) (Low level audio API)\n    - [miniaudio_engine.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/miniaudio/miniaudio_engine.nelua) (High level audio API)\n* [minifs](https://github.com/mackron/minifs)\n    - [minifs.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/minifs/minifs.nelua) (File system library)\n* [miniphysfs](https://github.com/edubart/miniphysfs) (PhysFS)\n    - [miniphysfs.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/miniphysfs/miniphysfs.nelua) (Archive filesystem)\n* [STB](https://github.com/nothings/stb)\n    - [stb_image.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/stb/stb_image.nelua) (Read images)\n    - [stb_image_write.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/stb/stb_image_write.nelua) (Write images)\n    - [stb_image_resize.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/stb/stb_image_resize.nelua) (Resize images)\n    - [stb_truetype.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/stb/stb_truetype.nelua) (Read TTF font files)\n    - [stb_vorbis.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/stb/stb_vorbis.nelua) (Read OGG sound files)\n* [Sokol](https://floooh.github.io/sokol-html5/index.html)\n    - [sokol_app.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_app.nelua) (Platform window manipulation)\n    - [sokol_args.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_args.nelua) (Platform command line arguments parser)\n    - [sokol_audio.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_audio.nelua) (Platform low level audio)\n    - [sokol_gfx.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_gfx.nelua) (Platform graphics API)\n    - [sokol_glue.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_glue.nelua)\n    - [sokol_time.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_time.nelua) (Platform time utilities)\n    - [sokol_nuklear.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_nuklear.nelua) (Sokol backend for Nuklear)\n    - [sokol_gl.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_gl.nelua) (Sokol 3D painter)\n    - [sokol_gp.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sokol/sokol_gp.nelua) (Sokol 2D painter)\n* [Blend2D](https://blend2d.com/)\n    - [blend2d.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/blend2d/blend2d.nelua) (2D vector graphics engine)\n* [Chipmunk](https://chipmunk-physics.net/)\n    - [chipmunk.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/chipmunk/chipmunk.nelua) (2D physics library)\n* [Raylib](https://www.raylib.com/)\n    - [raylib.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/raylib/raylib.nelua) (Simple library for creating games)\n* [libuv](https://libuv.org/)\n    - [uv.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/uv/uv.nelua) (Asynchronous I/O)\n* [enet](https://github.com/zpl-c/enet)\n    - [enet.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/enet/enet.nelua) (Reliable UDP networking library)\n* [znet](https://github.com/starwing/znet)\n    - [znet.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/znet/znet.nelua) (Simple TCP/UDP networking library)\n* [curl](https://curl.se/)\n    - [curl.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/curl/curl.nelua) (Utility for HTTP request and URL data transfer)\n* [mongoose](https://github.com/cesanta/mongoose)\n    - [mongoose.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/mongoose/mongoose.nelua) (Embedded web server\nand multi-protocol networking library)\n* [dmon](https://github.com/septag/dmon)\n    - [dmon.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/dmon/dmon.nelua) (Watch file changes in a directory)\n* [c89thread](https://github.com/mackron/c89thread) and [c89atomic](https://github.com/mackron/c89atomic)\n    - [c89thread.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/c89thread/c89thread.nelua) (Threading library)\n    - [c89atomic.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/c89thread/c89atomic.nelua) (Atomics library)\n* [subprocess](https://github.com/sheredom/subprocess.h)\n    - [subprocess.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/subprocess/subprocess.nelua) (Process launching library)\n* [mjson](https://github.com/cesanta/mjson)\n    - [mjson.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/mjson/mjson.nelua) (Lightweight JSON parser/emitter library)\n* [cJSON](https://github.com/DaveGamble/cJSON)\n    - [cJSON.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/cJSON/cJSON.nelua) (Easy JSON parser/emitter library)\n* [sqlite3](https://www.sqlite.org/)\n    - [sqlite3.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/sqlite3/sqlite3.nelua) (SQLite3 database)\n* [nuklear](https://github.com/Immediate-Mode-UI/Nuklear)\n    - [nuklear.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/nuklear/nuklear.nelua) (Immediate UI library)\n* [mbedtls](https://github.com/ARMmbed/mbedtls)\n    - [nuklear.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/mbedtls/mbedtls.nelua) (Cryptographic library)\n* [MIR](https://github.com/vnmakarov/mir)\n    - [mir.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/mir/mir.nelua) (A lightweight JIT compiler and C11 JIT compiler/interpreter based on MIR)\n* [Lexbor](http://lexbor.com/)\n    - [lexbor.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/lexbor/lexbor.nelua) (HTML/CSS/DOM parser/engine)\n* [tree-sitter](https://tree-sitter.github.io/tree-sitter/)\n    - [tree-sitter.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/tree-sitter/tree-sitter.nelua) (A parser generator tool and an incremental parsing library)\n* [microui](https://github.com/rxi/microui)\n    - [microui.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/microui/microui.nelua) (A tiny, portable, immediate-mode UI library)\n* [msf_gif](https://github.com/notnullnotvoid/msf_gif)\n    - [msf_gif.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/msf_gif/msf_gif.nelua) (A single-header animated GIF exporter)\nPlus the following platform specific libraries:\n* dl\n    - [dl.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/dl/dl.nelua) (Unix dynamic library loader)\n* [pthread](https://computing.llnl.gov/tutorials/pthreads/)\n    - [pthread.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/pthread/pthread.nelua) (POSIX threads)\n* [POSIX](https://en.wikipedia.org/wiki/POSIX)\n    - [unistd.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/unistd.nelua) (Essential POSIX functions)\n    - [dirent.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/dirent.nelua) (Directory control options)\n    - [errno.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/errno.nelua) (Error handling)\n    - [fcntl.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/fcntl.nelua) (File control options)\n    - [signal.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/signal.nelua) (Signal handling)\n    - [termios.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/termios.nelua) (Manipulate terminal I/O)\n    - [time.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/time.nelua) (Date and time)\n    - [sys/stat.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/posix/sys/stat.nelua) (File attributes)\n    - And some other POSIX APIs, check [the directory](https://github.com/edubart/nelua-decl/blob/main/libs/posix/)\n* Linux\n    - [inotify.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/linux/inotify.nelua) (Linux filesystem watcher)\n    - [epoll.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/linux/epoll.nelua) (Linux I/O event notification facility)\n    - [iouring.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/linux/iouring.nelua) (Linux newest IO interface)\n* Windows\n    - [windows.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/windows/windows.nelua) (Windows APIs)\n* Emscripten\n    - [emscripten.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/emscripten/emscripten.nelua) (Emscripten APIs)\n* X11\n    - [x11.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/x11/x11.nelua) (X11 Window APIs)\n* [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime)\n    - [wamr.nelua](https://github.com/edubart/nelua-decl/blob/main/libs/wamr/wamr.nelua) (WASM Micro Runtime APIs)\n\n## How to generate bindings\n\nMake sure you are using Lua 5.3+, GCC 9+ and have GCC plugin installed.\n\nFirst clone and compile the `gcc-lua` plugin and compile it:\n\n```bash\ngit clone --recurse-submodules https://github.com/edubart/nelua-decl.git\nmake -C gcc-lua\n```\n\nSome libraries such as SDL2, GLFW must be installed on your system.\n\nTo generate bindings for a library simply do `make generate` in its folder.\nFor example, the following will generate `libs/sdl2/sdl2.nelua` and\nthen run a test to check if it's working:\n\n```sh\ncd libs/sdl2\nmake generate\nmake test\n```\n\nSome single header libraries you must be downloaded with `make download`, for example:\n\n```sh\ncd libs/minilua\nmake download\nmake generate\nmake test\n```\n\n## How to generate bindings for a new library\n\nSuppose you want generate bindings for `mylib`, create a new folder `mylib` in `libs/`,\nthen you must create the following files:\n\n* mylib.c - A C file including all C headers that have the functions we want to bind.\n* mylib.lua - A lua file with binding generator rules.\n* Makefile - A Makefile script to assist generating the bindings.\n\nFor a quick start, see the `Makefile`, `.lua` and `.c` files of the current\nbundled libraries as an example.\n\n## How it works\n\nThe bindings are generated using the following command:\n\n```bash\ngcc -S libs/lua/lua.c \\\n    -fplugin=./gcc-lua/gcc/gcclua.so \\\n    -fplugin-arg-gcclua-script=libs/lua/lua.lua \\\n    \u003e libs/lua/lua.nelua\n```\n\nCommand explanation:\n\n* `-S libs/lua/lua.c` tells GCC to compile only the assembly instructions for the file, this is sufficient for parsing.\n* `-fplugin=./gcc-lua/gcc/gcclua.so` tells GCC to load the gcc-lua plugin before compiling.\n* `-fplugin-arg-gcclua-script=libs/lua/lua.lua` is the lua script loaded with configurations to generate the bindings.\n* `libs/lua/lua.nelua` is the output file.\n\n\n## Caveats\n\nSome limitations:\n\n* C bit fields are not supported.\n* C unnamed fields are not supported.\n* C math complex type is not supported.\n* C macros are hidden and requires some manual work to expose them.\n* Currently GCC plugin does not work on Windows, thus you have to generate bindings from a Linux machine.\n\nUsually to create bindings for a new library requires little manual work for C libraries\nthat are binding friendly to other languages.\nA binding friendly C libraries have the following characteristics:\n\n* No use of platform dependent function declarations, constants and structs in its API.\n* Constants are declared as enums instead of macros.\n* Functions are declared as C functions and not macros.\n* It doesn't use unnamed fields.\n* It doesn't use bit fields.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedubart%2Fnelua-decl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedubart%2Fnelua-decl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedubart%2Fnelua-decl/lists"}