Skip to content

Standard way to annotate ffi.cdef #2154

@GiuseppeIII

Description

@GiuseppeIII

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUser has a question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions