summaryrefslogtreecommitdiff
path: root/meta/template/ffi.lua
blob: e3a09ea1e45755c63165e637aa7a19abbf4f69d0 (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
---#if not JIT then DISABLE() end
---@meta

---@class ffi.namespace*: table

---@class ffi.cdecl*: string
---@class ffi.ctype*: userdata
local ctype
---@class ffi.cdata*: userdata
---@alias ffi.ct*     ffi.cdecl*|ffi.ctype*|ffi.cdata*
---@class ffi.cb*:    userdata
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 = {}

---@alias ffi* ffilib

---@param def string
function ffi.cdef(def) end

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

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

---@param nelem? integer
---@param init?  any
---@return ffi.cdata* cdata
function ctype(nelem, init, ...) end

---@param ct ffi.ct*
---@return ffi.ctype* ctype
function ffi.typeof(ct) end

---@param ct   ffi.ct*
---@param init any
---@return ffi.cdata* cdata
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
function ffi.sizeof(ct, nelem) end

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

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

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

---@param newerr? integer
---@return integer err
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