summaryrefslogtreecommitdiff
path: root/meta/template/ffi.lua
blob: 2ca83dd5c1d6289e81b05e8ca2595daf5724c0c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---#if not JIT then DISABLE() end
---@meta

---@class ffi.namespace*: table
---@field [string] function

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

---@class ffi.cdecl*: string
---@class ffi.cdata*: userdata
---@alias ffi.ct*     ffi.ctype*|ffi.cdecl*|ffi.cdata*
---@class ffi.cb*:    ffi.cdata*
local cb
---@class ffi.VLA*:   userdata
---@class ffi.VLS*:   userdata

---@version JIT
---@class ffilib
---@field C    ffi.namespace*
---@field os   string
---@field arch string
local ffi = {}

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

---@param name    string
---@param global? boolean
---@return ffi.namespace* clib
---@nodiscard
function ffi.load(name, global) end

---@overload fun(ct: ffi.ct*, init: any, ...)
---@param ct     ffi.ct*
---@param nelem? integer
---@param init?  any
---@return ffi.cdata* cdata
---@nodiscard
function ffi.new(ct, nelem, init, ...) end

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

---@param ct   ffi.ct*
---@param init any
---@return ffi.cdata* cdata
---@nodiscard
function ffi.cast(ct, init) end

---@param ct        ffi.ct*
---@param metatable table
---@return ffi.ctype* ctype
function ffi.metatype(ct, metatable) end

---@param cdata     ffi.cdata*
---@param finalizer? function
---@return ffi.cdata* cdata
function ffi.gc(cdata, finalizer) end

---@param ct     ffi.ct*
---@param nelem? integer
---@return integer|nil size
---@nodiscard
function ffi.sizeof(ct, nelem) end

---@param ct ffi.ct*
---@return integer align
---@nodiscard
function ffi.alignof(ct) end

---@param ct    ffi.ct*
---@param field string
---@return integer  ofs
---@return integer? bpos
---@return integer? bsize
---@nodiscard
function ffi.offsetof(ct, field) end

---@param ct  ffi.ct*
---@param obj any
---@return boolean status
---@nodiscard
function ffi.istype(ct, obj) end

---@param newerr? integer
---@return integer err
---@nodiscard
function ffi.errno(newerr) end

---@param ptr  any
---@param len? integer
---@return string str
function ffi.string(ptr, len) end

---@overload fun(dst: any, str: string)
---@param dst any
---@param src any
---@param len integer
function ffi.copy(dst, src, len) end

---@param dst any
---@param len integer
---@param c?  any
function ffi.fill(dst, len, c) end

---@param param string
---@return boolean status
function ffi.abi(param) end

function cb:free() end

---@param func function
function cb:set(func) end

return ffi