Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/fork/main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Mar 28, 2023
2 parents 22239e8 + b14a55b commit e12c84f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions packages/win32-def/src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ export function StructType<T extends StructDefType>(
input: T,
options?: StructCharOptions,
): StructTypeConstructor<T> {

const initType = genInitTyp(input, options)
// @ts-ignore
return Struct(initType)
return genInitTyp<T>(input, options)
}
export function StructFactory<T>(input: StructDefType, options?: StructCharOptions): T {
const initType = genInitTyp(input, options)
// @ts-ignore
return new Struct(initType)() as unknown as T
return new genInitTyp<T>(input, options)()
}

function genInitTyp(input: StructDefType, options?: StructCharOptions): StructDefType {
function genInitTyp(input: StructDefType, options?: StructCharOptions): StructTypeConstructor {
const opts: Required<StructCharOptions> = {
...defaultStructCharOptions,
...options,
Expand All @@ -61,14 +58,20 @@ function genInitTyp(input: StructDefType, options?: StructCharOptions): StructDe
&& opts.CharDefs.includes(value)) {

initType[key] = wcharBuffer(opts.maxCharLength)
}
else {
// @TODO recursive convertion
} else if (
typeof value === 'object'
&& value
// This is the same check "ref-napi" does to determine if the type
&& !('size' in value && 'indirection' in value)
) {
initType[key] = genInitTyp(value as StructDefType, options) as StructTypeConstructor
} else {
initType[key] = value
}
})

return initType
// @ts-ignore
return Struct(initType)
}

export interface StructCharOptions {
Expand Down
4 changes: 2 additions & 2 deletions packages/win32-def/src/lib/struct/struct.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export type LPRECT = _POINTER

export interface WINDOWINFO extends StructInstanceBase {
cbSize: DWORD
rcWindow: VOID
rcClient: VOID
rcWindow: RECT
rcClient: RECT
dwStyle: DWORD
dwExStyle: DWORD
dwWindowStatus: DWORD
Expand Down

0 comments on commit e12c84f

Please sign in to comment.