mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
chore(types): fix incorrect function signatures
* Fixes incorrect function signatures for callables. * Now correctly returns the main module.
This commit is contained in:
parent
d27fba8147
commit
991ae5a9f1
1 changed files with 100 additions and 85 deletions
185
types/ffi.luau
185
types/ffi.luau
|
@ -1,49 +1,34 @@
|
||||||
local CType = {}
|
|
||||||
-- NOTE: T is a unique identifier for the `CType` and R is the closest Lua type.
|
-- NOTE: T is a unique identifier for the `CType` and R is the closest Lua type.
|
||||||
export type CType<T, R> = typeof(CType) & {
|
export type CType<T, R> = {
|
||||||
size: number,
|
size: number,
|
||||||
signedness: boolean,
|
signedness: boolean,
|
||||||
|
|
||||||
|
ptr: (self: CType<T, R>) -> CPtr<R>,
|
||||||
|
box: (self: CType<T, R>, val: R) -> Box,
|
||||||
|
-- FIXME: recursive types; ud should be CTypes
|
||||||
|
from: (self: CType<T, R>, ud: any, offset: number?) -> R,
|
||||||
|
into: (self: CType<T, R>, ud: any, value: R, offset: number?) -> (),
|
||||||
|
arr: (self: CType<T, R>, len: number) -> CArr<R>,
|
||||||
|
-- FIXME: recursive types; intoType should be CTypes
|
||||||
|
cast: <F, I>(self: CType<T, R>, intoType: any, from: F, into: I) -> (),
|
||||||
} & { ["__phantom"]: T }
|
} & { ["__phantom"]: T }
|
||||||
|
|
||||||
function CType.ptr<T, R>(self: CType<T, R>): CPtr<R>
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
function CType.box<T, R>(self: CType<T, R>, val: R): Box
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
function CType.from<T, R>(self: CType<T, R>, ud: CTypes, offset: number?): R
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
function CType.into<T, R>(self: CType<T, R>, ud: CTypes, value: R, offset: number?)
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
function CType.arr<T, R>(self: CType<T, R>, len: number): CArr<R>
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
function CType.cast<T, R, F, I>(self: CType<T, R>, intoType: CTypes, from: F, into: I)
|
|
||||||
return nil :: any
|
|
||||||
end
|
|
||||||
|
|
||||||
export type CPtr<T> = {
|
export type CPtr<T> = {
|
||||||
size: number,
|
size: number,
|
||||||
inner: T?,
|
inner: T?,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CArr<T> = {
|
export type CArr<T> = {
|
||||||
size: number,
|
size: number,
|
||||||
length: number,
|
length: number,
|
||||||
inner: {T}?,
|
inner: { T }?,
|
||||||
|
|
||||||
offset: (self: CArr<T>, offset: number) -> number,
|
offset: (self: CArr<T>, offset: number) -> number,
|
||||||
ptr: (self: CArr<T>) -> CPtr<{T}>,
|
ptr: (self: CArr<T>) -> CPtr<{ T }>,
|
||||||
box: (self: CArr<T>, table: { T }) -> Box,
|
box: (self: CArr<T>, table: { T }) -> Box,
|
||||||
from: (self: CArr<T>, ud: CTypes, offset: number?) -> { T },
|
-- FIXME: recursive types; ud should be CTypes
|
||||||
into: (self: CArr<T>, ud: CTypes, value: { T }, offset: number?) -> (),
|
from: (self: CArr<T>, ud: any, offset: number?) -> { T },
|
||||||
|
into: (self: CArr<T>, ud: any, value: { T }, offset: number?) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
type NumCType<T> = CType<T, number>
|
type NumCType<T> = CType<T, number>
|
||||||
|
@ -80,82 +65,112 @@ export type longlong = NumCType<"longlong">
|
||||||
export type ulonglong = NumCType<"ulonglong">
|
export type ulonglong = NumCType<"ulonglong">
|
||||||
|
|
||||||
export type CFn = {
|
export type CFn = {
|
||||||
caller: () -> Callable
|
caller: (self: CFn, fnPtr: Ref) -> Callable,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CTypes =
|
export type CTypes =
|
||||||
| u8
|
u8
|
||||||
| u16
|
| u16
|
||||||
| u32
|
| u32
|
||||||
| u64
|
| u64
|
||||||
| u128
|
| u128
|
||||||
| i8
|
| i8
|
||||||
| i16
|
| i16
|
||||||
| i32
|
| i32
|
||||||
| i64
|
| i64
|
||||||
| i128
|
| i128
|
||||||
| f32
|
| f32
|
||||||
| f64
|
| f64
|
||||||
| usize
|
| usize
|
||||||
| isize
|
| isize
|
||||||
| char
|
| char
|
||||||
| float
|
| float
|
||||||
| double
|
| double
|
||||||
| uchar
|
| uchar
|
||||||
| schar
|
| schar
|
||||||
| short
|
| short
|
||||||
| ushort
|
| ushort
|
||||||
| int
|
| int
|
||||||
| uint
|
| uint
|
||||||
| long
|
| long
|
||||||
| ulong
|
| ulong
|
||||||
| longlong
|
| longlong
|
||||||
| ulonglong
|
| ulonglong
|
||||||
|
|
||||||
export type Ref = {
|
export type Ref = {
|
||||||
deref: (self: Ref) -> Ref,
|
deref: (self: Ref) -> Ref,
|
||||||
offset: (self: Ref, offset: number) -> Ref,
|
offset: (self: Ref, offset: number) -> Ref,
|
||||||
ref: (self: Ref) -> Ref,
|
ref: (self: Ref) -> Ref,
|
||||||
isNullptr: (self: Ref) -> boolean,
|
isNullptr: (self: Ref) -> boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Box = {
|
export type Box = {
|
||||||
size: number,
|
size: number,
|
||||||
|
|
||||||
zero: (self: Box) -> Box,
|
zero: (self: Box) -> Box,
|
||||||
leak: (self: Box, offset: number?) -> Ref,
|
leak: (self: Box, offset: number?) -> Ref,
|
||||||
ref: (self: Box, offset: number?) -> Ref,
|
ref: (self: Box, offset: number?) -> Ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Library = {
|
export type Library = {
|
||||||
find: (sym: string) -> Ref,
|
find: (self: Library, sym: string) -> Ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Callable = {
|
export type Callable = {
|
||||||
call: (...any) -> (),
|
call: (self: Callable, retPtr: Ref, ...Box) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
local ffi = {}
|
local ffi = {}
|
||||||
|
|
||||||
ffi.u8 = {} :: u8
|
ffi.u8 = (nil :: unknown) :: u8
|
||||||
|
ffi.u16 = {} :: u16
|
||||||
|
ffi.u32 = {} :: u32
|
||||||
|
ffi.u64 = {} :: u64
|
||||||
|
ffi.u128 = {} :: u128
|
||||||
|
ffi.i8 = {} :: i8
|
||||||
|
ffi.i16 = {} :: i16
|
||||||
|
ffi.i32 = {} :: i32
|
||||||
|
ffi.i64 = {} :: i64
|
||||||
|
ffi.i128 = {} :: i128
|
||||||
|
ffi.f32 = {} :: f32
|
||||||
|
ffi.f64 = {} :: f64
|
||||||
|
ffi.usize = {} :: usize
|
||||||
|
ffi.isize = {} :: isize
|
||||||
|
|
||||||
|
ffi.char = {} :: char
|
||||||
|
ffi.float = {} :: float
|
||||||
|
ffi.double = {} :: double
|
||||||
|
ffi.uchar = {} :: uchar
|
||||||
|
ffi.schar = {} :: schar
|
||||||
|
ffi.short = {} :: short
|
||||||
|
ffi.ushort = {} :: ushort
|
||||||
|
ffi.int = {} :: int
|
||||||
|
ffi.uint = {} :: uint
|
||||||
|
ffi.long = {} :: long
|
||||||
|
ffi.ulong = {} :: ulong
|
||||||
|
ffi.longlong = {} :: longlong
|
||||||
|
ffi.ulonglong = {} :: ulonglong
|
||||||
|
|
||||||
ffi.nullptr = {} :: Ref
|
ffi.nullptr = {} :: Ref
|
||||||
|
|
||||||
function ffi.box(size: number): Box
|
function ffi.box(size: number): Box
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function ffi.open(path: string): Library
|
function ffi.open(path: string): Library
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function ffi.ref(): Ref
|
function ffi.ref(): Ref
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function ffi.isInteger<T>(val: T): boolean
|
function ffi.isInteger<T>(val: T): boolean
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
function ffi.fn<T>(args: { any }, ret: CPtr<T>): CFn
|
function ffi.fn<T>(args: { CTypes }, ret: CTypes): CFn
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return ffi
|
||||||
|
|
Loading…
Add table
Reference in a new issue