@@ -22,8 +22,9 @@ export type CPtrInfo<T> = {
22
22
inner : T ,
23
23
24
24
-- subtype
25
- -- FIXME: recursive types; 'any' should be CPtrInfo
25
+ -- FIXME: recursive types; result 'any' should be CArrInfo< CPtrInfo<T>>
26
26
arr : (self : CPtrInfo <T >, len : number ) -> any ,
27
+ -- FIXME: recursive types; result 'any' should be CPtrInfo<CPtrInfo<T>>
27
28
ptr : (self : CPtrInfo <T >) -> any ,
28
29
29
30
readRef : (self : CPtrInfo <T >, target : (Ref | Box ), offset : number ? ) -> Ref ,
@@ -36,12 +37,12 @@ export type CArrInfo<T, R> = {
36
37
inner : T ,
37
38
38
39
-- subtype
39
- ptr : (self : CArrInfo <T , R >) -> CPtrInfo <T >,
40
+ ptr : (self : CArrInfo <T , R >) -> CPtrInfo <CArrInfo < T , R > >,
40
41
41
42
-- realize
42
43
box : (self : CArrInfo <T , R >, table : { T }) -> Box ,
43
44
readData : (self : CArrInfo <T , R >, target : (Ref | Box ), offset : number ? ) -> { T },
44
- writeData : (self : CArrInfo <T , R >, target : (Ref | Box ), value : { T }, offset : number ? ) -> (),
45
+ writeData : (self : CArrInfo <T , R >, target : (Ref | Box ), value : { R }, target_offset : number ? ) -> (),
45
46
copyData : (self : CArrInfo <T , R >, dst : (Ref | Box ), src : (Ref | Box ), dst_offset : number ? , src_offset : number ? ) -> (),
46
47
47
48
offset : (self : CArrInfo <T , R >, index : number ) -> number ,
@@ -145,20 +146,82 @@ export type Ref = {
145
146
isNull : (self : Ref ) -> boolean ,
146
147
}
147
148
149
+ --[=[
150
+ @class Box
151
+
152
+ A user manageable heap memory
153
+ ]=]
148
154
export type Box = {
155
+ --[=[
156
+ @within Box
157
+ @tag Field
158
+ @field size
159
+
160
+ Size of the box.
161
+ ]=]
149
162
size : number ,
150
163
164
+ --[=[
165
+ @within Box
166
+ @tag Method
167
+ @method zero
168
+
169
+ Fill the box with zero.
170
+
171
+ @return `Box` itself for convenience
172
+ ]=]
151
173
zero : (self : Box ) -> Box ,
174
+ --[=[
175
+ @within Box
176
+ @tag Method
177
+ @method leak
178
+
179
+ Create a reference of the box after leaking it.
180
+
181
+ GC doesn't manage destruction after this action. You must free it later
182
+
183
+ @return A reference of the box
184
+ ]=]
152
185
leak : (self : Box , offset : number ? ) -> Ref ,
186
+ --[=[
187
+ @within Box
188
+ @tag Method
189
+ @method ref
190
+
191
+ Create a reference of the box.
192
+
193
+ @return A reference of the box
194
+ ]=]
153
195
ref : (self : Box , offset : number ? ) -> Ref ,
154
196
}
155
197
198
+ --[=[
199
+ @class Lib
200
+
201
+ A dynamic opened library handle
202
+ ]=]
156
203
export type Lib = {
204
+ --[=[
205
+ @within Lib
206
+ @tag Method
207
+ @method find
208
+
209
+ Find a symbol from the dynamic library.
210
+
211
+ @param sym The name of the symbol
212
+ @return A `Ref` of the found symbol
213
+ ]=]
157
214
find : (self : Lib , sym : string ) -> Ref ,
158
215
}
159
216
160
217
-- export type AppliedCallable = ()->()
161
218
219
+ --[=[
220
+ @class Callable
221
+ @tag unsafe
222
+
223
+ A callable external function
224
+ ]=]
162
225
export type Callable = (ret : (Ref | Box )? , ...Ref )-> () & {
163
226
-- apply: (self: Callable, args: Args)->AppliedCallable,
164
227
}
@@ -167,6 +230,12 @@ export type Closure = {
167
230
ref : (self : Closure )-> Ref ,
168
231
}
169
232
233
+ --[=[
234
+ @class C
235
+ @within FFI
236
+
237
+ Namespace for compile time sized c types.
238
+ ]=]
170
239
local c = {}
171
240
172
241
c .char = {} :: char
@@ -185,14 +254,41 @@ c.ulonglong = {} :: ulonglong
185
254
186
255
c .void = {} :: CVoidInfo
187
256
257
+ --[=[
258
+ @within C
259
+
260
+ Create a function signature type information.
261
+
262
+ @param args An array of CTypes represents the arguments of the function
263
+ @param ret The return type of the function
264
+ @return A function signature type information
265
+ ]=]
188
266
function c .fn (args : { CTypes }, ret : CTypes ): CFnInfo
189
267
return nil :: any
190
268
end
191
269
192
- function c .struct (inner : { CTypes }): CStructInfo
270
+ --[=[
271
+ @within C
272
+
273
+ Create a struct type information.
274
+
275
+ @param fields An array of CTypes represents the fields of the struct
276
+ @return A struct type information
277
+ ]=]
278
+ function c .struct (fields : { CTypes }): CStructInfo
193
279
return nil :: any
194
280
end
195
281
282
+ --[=[
283
+ @class FFI
284
+
285
+ Built-in library for foreign function interface
286
+
287
+ ### Example usage
288
+
289
+ ```lua
290
+ ```
291
+ ]=]
196
292
local ffi = {}
197
293
198
294
ffi .c = c
@@ -212,22 +308,51 @@ ffi.f64 = {} :: f64
212
308
ffi .usize = {} :: usize
213
309
ffi .isize = {} :: isize
214
310
311
+ --[=[
312
+ @within FFI
313
+
314
+ Create a `Ref` with address 0.
315
+
316
+ Can be used for receive a pointer from external function or pass it as an argument.
317
+
318
+ @return A zero initialized Ref
319
+ ]=]
215
320
function ffi .nullRef (): Ref
216
321
return nil :: any
217
322
end
218
323
324
+ --[=[
325
+ @within FFI
326
+
327
+ Create a `Box` with specific size.
328
+
329
+ @param size The size of the new box
330
+ @return A allocated box
331
+ ]=]
219
332
function ffi .box (size : number ): Box
220
333
return nil :: any
221
334
end
222
335
336
+ --[=[
337
+ @within FFI
338
+
339
+ Open a dynamic library.
340
+
341
+ @param name The name of the target library
342
+ @return A dynamic library handle
343
+ ]=]
223
344
function ffi .open (name : string ): Lib
224
345
return nil :: any
225
346
end
226
347
227
- function ffi .uninitRef (): Ref
228
- return nil :: any
229
- end
348
+ --[=[
349
+ @within FFI
350
+
351
+ Return `true` if the second argument is an integer (i32)
230
352
353
+ @param val A lua value to check
354
+ @return Whether val is an integer or not
355
+ ]=]
231
356
function ffi .isInteger <T >(val : T ): boolean
232
357
return nil :: any
233
358
end
0 commit comments