Skip to content

Fix ffi meta#1681

Merged
sumneko merged 1 commit into
LuaLS:masterfrom
Lyrth:fix--ffi-meta
Nov 9, 2022
Merged

Fix ffi meta#1681
sumneko merged 1 commit into
LuaLS:masterfrom
Lyrth:fix--ffi-meta

Conversation

@Lyrth
Copy link
Copy Markdown
Contributor

@Lyrth Lyrth commented Nov 9, 2022

Fix some behavior in ffi meta


---@field [string] function

1 - Fixes below issue when C functions are accessed from namespace tables.
image


---@overload fun(init?: any, ...): ffi.cdata*
---@overload fun(nelem?: integer, init?: any, ...): ffi.cdata*

2 - ctype isn't a function, it says that ffi.ctype* can be called like a constructor (see Calling a cdata object section):

Calling a cdata object
Constructor: a ctype object can be called and used as a constructor. This is equivalent to ffi.new(ct, ...), unless a __new metamethod is defined.

image


---@class ffi.cb*:    ffi.cdata*

3 - cb types can only come from ffi.new or ffi.cast, e.g.: ffi.cast('int (*)()', function() return 1 end)


---@param params? any
function ffi.cdef(def, params, ...) end

4 - ffi.cdef and ffi.typeof accepts "parameters" for cdecls containing $ (see Parameterized Types section):

Any place you can write a typedef name, an identifier or a number in a declaration, you can write $ (the dollar sign) instead. These placeholders are replaced in order of appearance with the arguments following the cdecl string

image


---@overload fun(ct: ffi.ct*, init: any, ...)

5 - Prevent the following issue from happening (when nelem is skipped and init is meant to be specified):
image


( Removal of ffi.ctype )
6 - see issue 2 above


---@param params? any
---@return ffi.ctype* ctype
---@nodiscard
function ffi.typeof(ct, params, ...) end

7 - see issue 4 above


---@nodiscard
function ffi.cast(ct, init) end

8 - ---@nodiscard is useful here because casts are always meant to be used in ffi.

@sumneko
Copy link
Copy Markdown
Collaborator

sumneko commented Nov 9, 2022

Thank you!

@sumneko sumneko merged commit 0eec0d9 into LuaLS:master Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants