{"id":33180161,"url":"https://github.com/jmckaskill/luaffi","last_synced_at":"2025-11-16T16:01:05.730Z","repository":{"id":41055425,"uuid":"2002714","full_name":"jmckaskill/luaffi","owner":"jmckaskill","description":"Standalone FFI library for calling C functions from lua. Compatible with the luajit FFI interface.","archived":true,"fork":false,"pushed_at":"2020-12-19T19:26:32.000Z","size":551,"stargazers_count":464,"open_issues_count":38,"forks_count":84,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-05-02T13:21:23.748Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/jmckaskill.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}},"created_at":"2011-07-05T20:25:36.000Z","updated_at":"2024-04-27T20:13:31.000Z","dependencies_parsed_at":"2022-09-20T22:00:21.098Z","dependency_job_id":null,"html_url":"https://github.com/jmckaskill/luaffi","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jmckaskill/luaffi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmckaskill%2Fluaffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmckaskill%2Fluaffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmckaskill%2Fluaffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmckaskill%2Fluaffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmckaskill","download_url":"https://codeload.github.com/jmckaskill/luaffi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmckaskill%2Fluaffi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284734138,"owners_count":27054622,"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","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-11-16T03:00:39.950Z","updated_at":"2025-11-16T16:01:05.722Z","avatar_url":"https://github.com/jmckaskill.png","language":"C","funding_links":[],"categories":["资源","Foreign Function Interface","Resources"],"sub_categories":["Foreign Function Interfaces"],"readme":"About\r\n-----\r\nThis is a library for calling C function and manipulating C types from lua. It\r\nis designed to be interface compatible with the FFI library in luajit (see\r\nhttp://luajit.org/ext_ffi.html). It can parse C function declarations and\r\nstruct definitions that have been directly copied out of C header files and\r\ninto lua source as a string.\r\n\r\nLicense\r\n-------\r\nCopyright (c) 2011 James R. McKaskill.\r\nMIT same as Lua 5.1. See full license text in ffi.h.\r\n\r\nSource\r\n------\r\nhttps://github.com/jmckaskill/luaffi\r\n\r\nPlatforms\r\n---------\r\nCurrently supported:\r\n- windows x86/x64\r\n- linux x86/x64\r\n- windows CE ARM little endian (ARMv4+)\r\n- OSX x86/x64\r\n\r\nCurrently only dll builds are supported (ie no static).\r\n\r\nRuns with both Lua 5.1 and Lua 5.2 beta.\r\n\r\nBuild\r\n-----\r\n\r\nOn windows use msvcbuild.bat in a visual studio cmd prompt. Available targets are:\r\n- nothing or release: default release build\r\n- debug: debug build\r\n- test: build and run the test debug build\r\n- test-release: build and run the test release build\r\n- clean: cleanup object files\r\n\r\nEdit msvcbuild.bat if your lua exe, lib, lua include path, or lua dll name\r\ndiffer from c:\\Lua5.1 and lua5.1.dll.\r\n\r\nThe build script does not build for CE as this is non-trivial and very\r\ndependent on which CE profile (or even a custom one). Instead to build on CE,\r\nadd generate_call_h.bat as a pre-build event and then build *.c with UNDER_CE\r\ndefined plus whatever defines windows.h requires.\r\n\r\nOn posix use make. Available targets are:\r\n- nothing or all: default release build\r\n- debug: debug build\r\n- test: build and run the test build\r\n- clean: cleanup object files\r\n- macosx: release build for Mac OSX\r\n\r\nEdit the Makefile if your lua exe differs from `lua5.1` or if you can't get\r\nthe include and lib arguments from pkg-config.\r\n\r\nKnown Issues\r\n------------\r\n- Has not been bullet proof tested\r\n- Casting is different from luajit. For the moment this follows C++\r\n  - ffi.cast is equivalent to a C cast in C++ (T t = (T) f)\r\n  - ffi.new and ctype() is equivalent to an implicit cast in C++ (T t = f)\r\n     - since this follows C++ semantics void* does not cast to T* (an explicit\r\n       cast using ffi.cast is required)\r\n- Comparing a ctype pointer to nil doesn't work the same as luajit. This is\r\n  unfixable with the current metamethod semantics. Instead use ffi.C.NULL\r\n- Constant expressions can't handle non integer intermediate values (eg\r\n  offsetof won't work because it manipulates pointers)\r\n- Not all metamethods work with lua 5.1 (eg char* + number). This is due to\r\n  the way metamethods are looked up with mixed types in Lua 5.1. If you need\r\nthis upgrade to Lua 5.2 or use boxed numbers (uint64_t and uintptr_t).\r\n- All bitfields are treated as unsigned (does anyone even use signed\r\n  bitfields?). Note that \"int s:8\" is unsigned on unix x86/x64, but signed on\r\nwindows.\r\n\r\nTodo\r\n----\r\nSee Github issues for the most up to date list.\r\n- Fix arm support - broken since the callback refactor\r\n- Vectors\r\n- C++ reference types\r\n- Subtracting one pointer from another\r\n- Variable sized members in unions (is this needed?)\r\n\r\nHow it works\r\n------------\r\nTypes are represented by a struct ctype structure and an associated user value\r\ntable. The table is shared between all related types for structs, unions, and\r\nfunctions. It's members have the types of struct members, function argument\r\ntypes, etc. The struct ctype structure then contains the modifications from\r\nthe base type (eg number of pointers, array size, etc).\r\n\r\nTypes are pushed into lua as a userdata containing the struct ctype with a\r\nuser value (or fenv in 5.1) set to the shared type table.\r\n\r\nBoxed cdata types are pushed into lua as a userdata containing the struct\r\ncdata structure (which contains the struct ctype of the data as its header)\r\nfollowed by the boxed data.\r\n\r\nThe functions in ffi.c provide the cdata and ctype metatables and ffi.*\r\nfunctions which manipulate these two types.\r\n\r\nC functions (and function pointers) are pushed into lua as a lua c function\r\nwith the function pointer cdata as the first upvalue. The actual code is JITed\r\nusing dynasm (see call_x86.dasc). The JITed code does the following in order:\r\n1. Calls the needed unpack functions in ffi.c placing each argument on the HW stack\r\n2. Updates errno\r\n3. Performs the c call\r\n4. Retrieves errno\r\n5. Pushes the result back into lua from the HW register or stack\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmckaskill%2Fluaffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmckaskill%2Fluaffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmckaskill%2Fluaffi/lists"}