Skip to content

Commit

Permalink
pointer to pointer v2 (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
programmingkidx authored Jan 29, 2024
1 parent ccec524 commit 6a98f82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion generate/codegen/gen_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (m *Method) WriteGoCallCode(currentModule *modules.Module, typeName string,
for idx, p := range m.Params {
switch tt := p.Type.(type) {
case *typing.ClassType:
args = append(args, "objc.Ptr("+p.GoName()+")")
args = append(args, p.GoName())
case *typing.ProtocolType:
pvar := fmt.Sprintf("po%d", idx)
cw.WriteLineF("%s := objc.WrapAsProtocol(\"%s\", %s)", pvar, tt.Name, p.GoName())
Expand Down
11 changes: 9 additions & 2 deletions generate/codegen/gen_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ type Param struct {
Type typing.Type
FieldName string // objc param field name(part of function name)
Object bool // version of param generalized to IObject for protocols
IsPtrPtr bool
}

func (p *Param) String() string {
return p.FieldName + ":" + p.Name
}

// GoDeclare return go param declare code
// Return Go parameter code
func (p *Param) GoDeclare(currentModule *modules.Module, receiveFromObjc bool) string {
return p.GoName() + " " + p.Type.GoName(currentModule, receiveFromObjc)
returnValue := p.GoName() + " "
if p.IsPtrPtr == true { // Example: NSError **error
returnValue = returnValue + "unsafe.Pointer"
} else {
returnValue = returnValue + p.Type.GoName(currentModule, receiveFromObjc)
}
return returnValue
}

func (p *Param) ObjcDeclare() string {
Expand Down
1 change: 1 addition & 0 deletions generate/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (db *Generator) Members(fw string, sym Symbol, covariantTypes []string) (pr
Name: arg.Name,
Type: ptyp,
FieldName: st.Method.NameParts[idx],
IsPtrPtr: arg.Type.IsPtrPtr,
}
params = append(params, param)
}
Expand Down

0 comments on commit 6a98f82

Please sign in to comment.