LuaLS / LuaLS/lua-language-server
Standard way to annotate ffi.cdef
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
I have some ffi that looks like this
---@type ffilib
Connector.ffi = package.preload["ffi"]()
Connector.ffi.cdef [[
void curl_free_pointer(const char* string);
const char* curl_get(const char* query);
const char* curl_patch(const char* query, const char* body, bool return_patched);
const char* curl_post(const char* query, const char* body, bool merge_duplicates, bool ignore_duplicates, bool return_post);
]]
I am able to get nice typing on the Connector.ffi part through ---@type ffilib, but am not sure if there is a nice way to annotate the returns from these functions. A could wrap the c functions to lua functions and then annotate the lua functions, but I wasn't sure if there was a nice way to do it directly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing how ffi.cdef and the ffilib type are currently handled, then trace whether return types can be represented directly in that path. Done means there is a documented annotation approach for these C functions, with coverage showing that their return types are recognized without Lua wrapper functions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100