LuaLS / LuaLS/lua-language-server

Standard way to annotate ffi.cdef

Open
#2,154 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.