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
|
@ -1,34 +1,18 @@
|
|||
local CType = {}
|
||||
-- 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,
|
||||
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 }
|
||||
|
||||
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> = {
|
||||
size: number,
|
||||
inner: T?,
|
||||
|
@ -42,8 +26,9 @@ export type CArr<T> = {
|
|||
offset: (self: CArr<T>, offset: number) -> number,
|
||||
ptr: (self: CArr<T>) -> CPtr<{ T }>,
|
||||
box: (self: CArr<T>, table: { T }) -> Box,
|
||||
from: (self: CArr<T>, ud: CTypes, offset: number?) -> { T },
|
||||
into: (self: CArr<T>, ud: CTypes, value: { T }, offset: number?) -> (),
|
||||
-- FIXME: recursive types; ud should be CTypes
|
||||
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>
|
||||
|
@ -80,11 +65,11 @@ export type longlong = NumCType<"longlong">
|
|||
export type ulonglong = NumCType<"ulonglong">
|
||||
|
||||
export type CFn = {
|
||||
caller: () -> Callable
|
||||
caller: (self: CFn, fnPtr: Ref) -> Callable,
|
||||
}
|
||||
|
||||
export type CTypes =
|
||||
| u8
|
||||
u8
|
||||
| u16
|
||||
| u32
|
||||
| u64
|
||||
|
@ -128,16 +113,44 @@ export type Box = {
|
|||
}
|
||||
|
||||
export type Library = {
|
||||
find: (sym: string) -> Ref,
|
||||
find: (self: Library, sym: string) -> Ref,
|
||||
}
|
||||
|
||||
export type Callable = {
|
||||
call: (...any) -> (),
|
||||
call: (self: Callable, retPtr: Ref, ...Box) -> (),
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
function ffi.box(size: number): Box
|
||||
|
@ -156,6 +169,8 @@ function ffi.isInteger<T>(val: T): boolean
|
|||
return nil :: any
|
||||
end
|
||||
|
||||
function ffi.fn<T>(args: { any }, ret: CPtr<T>): CFn
|
||||
function ffi.fn<T>(args: { CTypes }, ret: CTypes): CFn
|
||||
return nil :: any
|
||||
end
|
||||
|
||||
return ffi
|
||||
|
|
Loading…
Add table
Reference in a new issue