From 53a6ec84dbcec544b704a373a41b1af8239f021d Mon Sep 17 00:00:00 2001 From: KaruroChori Date: Fri, 20 Sep 2024 14:18:39 +0100 Subject: [PATCH] Update parser.ts to support function callbacks in args Simple fix for https://github.com/Morglod/bun-ffi-gen/issues/4. Still, callback types are not generated, limiting the quality of the final bindings. --- src/parser.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/parser.ts b/src/parser.ts index 782ca0a..c4589be 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -255,6 +255,7 @@ export function parseClangAst(astJson: any[], headerFilePath: string, clangTypeI const constPtrMatch = qualType.match(/^const (?:struct\s)?(\w+) \*$/); const ptrMatch = qualType.match(/^(?:struct\s)?([\w\W\s]+)\s?\*(?:const)?$/); + const fnPtrMatch = qualType.match(/^^.*?\(\s*\*\s*([\w\W\s]*?)\s*\).*$/); if (constPtrMatch) { ptrBaseName = constPtrMatch[1]; @@ -263,6 +264,8 @@ export function parseClangAst(astJson: any[], headerFilePath: string, clangTypeI } else if (ptrMatch) { ptrBaseName = ptrMatch[1]; isPtr = true; + } else if (fnPtrMatch){ + isCallback = true; } if (isPtr) { @@ -281,6 +284,13 @@ export function parseClangAst(astJson: any[], headerFilePath: string, clangTypeI baseType: findDecl({ name: ptrBaseName }, true), } ); + } else if(isCallback){ + return { + type: "pointer", + is_const: false, + size: POINTER_SIZE, + baseType: findDecl({ name: 'void' }, true), + } } return findDeclOrThrow({ name: qualType }, true);