genbindings: call correct c++ function for optional parameters

This commit is contained in:
mappu 2024-08-10 11:45:19 +12:00
parent f9abbed9c7
commit 6fb50dc267
3 changed files with 14 additions and 7 deletions

View File

@ -235,6 +235,11 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
preamble, forwarding := emitParametersCABI2CppForwarding(m.Parameters)
nativeMethodName := m.MethodName
if m.OverrideMethodName != "" {
nativeMethodName = m.OverrideMethodName
}
ret.WriteString(fmt.Sprintf(
"%s %s_%s(%s) {\n"+
"%s"+
@ -244,7 +249,7 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
"\n",
emitReturnTypeCabi(m.ReturnType), c.ClassName, m.SafeMethodName(), emitParametersCabi(m, "P"+c.ClassName),
preamble,
shouldReturn, c.ClassName, m.MethodName, forwarding,
shouldReturn, c.ClassName, nativeMethodName, forwarding,
afterCall,
))
}

View File

@ -24,9 +24,10 @@ type CppProperty struct {
}
type CppMethod struct {
MethodName string
ReturnType CppParameter // Name not used
Parameters []CppParameter
MethodName string
OverrideMethodName string // Present only if we changed the target
ReturnType CppParameter // Name not used
Parameters []CppParameter
}
func (nm CppMethod) SafeMethodName() string {

View File

@ -29,9 +29,10 @@ func astTransformOptional(parsed *CppParsedHeader) {
// Add method copies
for x := optionalStart; x < len(m.Parameters); x++ {
dupMethod := CppMethod{
MethodName: m.MethodName + fmt.Sprintf("%d", x+1),
ReturnType: m.ReturnType,
Parameters: nil,
MethodName: m.MethodName + fmt.Sprintf("%d", x+1),
OverrideMethodName: m.MethodName,
ReturnType: m.ReturnType,
Parameters: nil,
}
dupMethod.Parameters = append(dupMethod.Parameters, m.Parameters[0:x+1]...)
c.Methods = append(c.Methods, dupMethod) // TODO can we insert them next, instead of at the end?