-
Notifications
You must be signed in to change notification settings - Fork 3.4k
embind: tsgen function params name #20141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
embind: tsgen function params name #20141
Conversation
Its a shame we can't extract the argument names from the C/C++ declarations.. but that would be highly non-trivial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor things and please add some tests to https://github.com/emscripten-core/emscripten/blob/main/test/other/embind_tsgen.cpp and update the expected defintions.
I would ultimately like to get to a situation where we extract argument names, but I think that will require a clang plugin or extracting the argument names from the debug info.
src/embind/embind_ts.js
Outdated
for (let i = argStart; i < argTypes.length; i++) { | ||
args.push(new Argument(`_${i - argStart}`, argTypes[i])); | ||
if (argsName.length && x < argsName.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add an assert that if argNames are used it matches the expected number of arguments. This will help prevent bindings getting out of sync with their TS definitions.
src/embind/embind_shared.js
Outdated
signature = signature.trim(); | ||
const argsIndex = signature.indexOf("(") + 1; | ||
if (argsIndex !== 0) { | ||
assert(signature[signature.length - 1] == ")", "Unmatching paranthesis for argument names."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added assertion for unmatching parenthesis in function signature
const returnType = argTypes[0]; | ||
let thisType = null; | ||
let argStart = 1; | ||
if (hasThis) { | ||
thisType = argTypes[1]; | ||
argStart = 2; | ||
} | ||
if (argsName.length) | ||
assert(argsName.length == (argTypes.length - hasThis - 1), 'Argument names should match number of parameters.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added assertions for argument names to match expected number of parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still missings tests in https://github.com/emscripten-core/emscripten/blob/main/test/other/embind_tsgen.cpp and update the expected defintions
src/embind/embind_shared.js
Outdated
signature = signature.trim(); | ||
const argsIndex = signature.indexOf("("); | ||
if (argsIndex !== -1) { | ||
assert(signature[signature.length - 1] == ")", "Unmatching paranthesis for argument names."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Parentheses for argument names should match.'
src/embind/embind_shared.js
Outdated
signature = signature.trim(); | ||
const argsIndex = signature.indexOf("(") + 1; | ||
if (argsIndex !== 0) { | ||
assert(signature[signature.length - 1] == ")", "Unmatching paranthesis for argument names."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Parentheses for argument names should match.'
…0/emscripten into tsgen-function-params-name
@tayyabejaz2000 @brendandahl This is a good idea until extracting names is possible. Quick question: what about constructors? Is there a solution available for those too? |
_<n>
convention