2
0
mirror of synced 2025-02-23 14:58:12 +00:00

bind: correct methods' return arg type mapping in obj-c binding.

Change-Id: Ieda05982c7f894c5603103b8890658e682e97423
Reviewed-on: https://go-review.googlesource.com/11307
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Hyang-Ah (Hana) Kim 2015-06-22 22:13:09 -04:00 committed by Hyang-Ah Hana Kim
parent 4d3dd47e87
commit 3a9b5b50ac
6 changed files with 67 additions and 9 deletions

View File

@ -254,7 +254,7 @@ func (s *funcSummary) asMethod(g *objcGen) string {
if len(params) > 0 || i > 0 { if len(params) > 0 || i > 0 {
key = p.name key = p.name
} }
params = append(params, fmt.Sprintf("%s:(%s)%s", key, g.objcType(p.typ), p.name)) params = append(params, fmt.Sprintf("%s:(%s)%s", key, g.objcType(p.typ)+"*", p.name))
} }
return fmt.Sprintf("(%s)%s%s", s.ret, s.name, strings.Join(params, " ")) return fmt.Sprintf("(%s)%s%s", s.ret, s.name, strings.Join(params, " "))
} }

View File

@ -13,6 +13,10 @@ func (s *S) Sum() float64 {
return s.X + s.Y return s.X + s.Y
} }
func (s *S) Identity() (*S, error) {
return s, nil
}
func Identity(s *S) *S { func Identity(s *S) *S {
return s return s
} }

View File

@ -36,7 +36,8 @@ const (
proxyS_X_Set_Code = 0x01f proxyS_X_Set_Code = 0x01f
proxyS_Y_Get_Code = 0x10f proxyS_Y_Get_Code = 0x10f
proxyS_Y_Set_Code = 0x11f proxyS_Y_Set_Code = 0x11f
proxyS_Sum_Code = 0x00c proxyS_Identity_Code = 0x00c
proxyS_Sum_Code = 0x10c
) )
type proxyS seq.Ref type proxyS seq.Ref
@ -65,6 +66,18 @@ func proxyS_Y_Get(out, in *seq.Buffer) {
out.WriteFloat64(v) out.WriteFloat64(v)
} }
func proxyS_Identity(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(*structs.S)
res, err := v.Identity()
out.WriteGoRef(res)
if err == nil {
out.WriteString("")
} else {
out.WriteString(err.Error())
}
}
func proxyS_Sum(out, in *seq.Buffer) { func proxyS_Sum(out, in *seq.Buffer) {
ref := in.ReadRef() ref := in.ReadRef()
v := ref.Get().(*structs.S) v := ref.Get().(*structs.S)
@ -77,6 +90,7 @@ func init() {
seq.Register(proxyS_Descriptor, proxyS_X_Get_Code, proxyS_X_Get) seq.Register(proxyS_Descriptor, proxyS_X_Get_Code, proxyS_X_Get)
seq.Register(proxyS_Descriptor, proxyS_Y_Set_Code, proxyS_Y_Set) seq.Register(proxyS_Descriptor, proxyS_Y_Set_Code, proxyS_Y_Set)
seq.Register(proxyS_Descriptor, proxyS_Y_Get_Code, proxyS_Y_Get) seq.Register(proxyS_Descriptor, proxyS_Y_Get_Code, proxyS_Y_Get)
seq.Register(proxyS_Descriptor, proxyS_Identity_Code, proxyS_Identity)
seq.Register(proxyS_Descriptor, proxyS_Sum_Code, proxyS_Sum) seq.Register(proxyS_Descriptor, proxyS_Sum_Code, proxyS_Sum)
} }

View File

@ -39,7 +39,8 @@ public abstract class Structs {
private static final int FIELD_X_SET = 0x01f; private static final int FIELD_X_SET = 0x01f;
private static final int FIELD_Y_GET = 0x10f; private static final int FIELD_Y_GET = 0x10f;
private static final int FIELD_Y_SET = 0x11f; private static final int FIELD_Y_SET = 0x11f;
private static final int CALL_Sum = 0x00c; private static final int CALL_Identity = 0x00c;
private static final int CALL_Sum = 0x10c;
private go.Seq.Ref ref; private go.Seq.Ref ref;
@ -83,6 +84,20 @@ public abstract class Structs {
Seq.send(DESCRIPTOR, FIELD_Y_SET, in, out); Seq.send(DESCRIPTOR, FIELD_Y_SET, in, out);
} }
public S Identity() throws Exception {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
S _result;
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_Identity, _in, _out);
_result = new S(_out.readRef());
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
return _result;
}
public double Sum() { public double Sum() {
go.Seq _in = new go.Seq(); go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq(); go.Seq _out = new go.Seq();

View File

@ -19,6 +19,7 @@
- (void)setX:(double)v; - (void)setX:(double)v;
- (double)Y; - (double)Y;
- (void)setY:(double)v; - (void)setY:(double)v;
- (BOOL)Identity:(GoStructs_S**)ret0_ error:(NSError**)error;
- (double)Sum; - (double)Sum;
@end @end

View File

@ -19,7 +19,8 @@ static NSString *errDomain = @"go.structs";
#define _GO_structs_S_FIELD_X_SET_ (0x01f) #define _GO_structs_S_FIELD_X_SET_ (0x01f)
#define _GO_structs_S_FIELD_Y_GET_ (0x10f) #define _GO_structs_S_FIELD_Y_GET_ (0x10f)
#define _GO_structs_S_FIELD_Y_SET_ (0x11f) #define _GO_structs_S_FIELD_Y_SET_ (0x11f)
#define _GO_structs_S_Sum_ (0x00c) #define _GO_structs_S_Identity_ (0x00c)
#define _GO_structs_S_Sum_ (0x10c)
@implementation GoStructs_S { @implementation GoStructs_S {
} }
@ -72,6 +73,29 @@ static NSString *errDomain = @"go.structs";
go_seq_free(&out_); go_seq_free(&out_);
} }
- (BOOL)Identity:(GoStructs_S**)ret0_ error:(NSError**)error {
GoSeq in_ = {};
GoSeq out_ = {};
go_seq_writeRef(&in_, self.ref);
go_seq_send(_GO_structs_S_DESCRIPTOR_, _GO_structs_S_Identity_, &in_, &out_);
GoSeqRef* ret0__ref = go_seq_readRef(&out_);
if (ret0_ != NULL) {
*ret0_ = ret0__ref.obj;
if (*ret0_ == NULL) {
*ret0_ = [[GoStructs_S alloc] initWithRef:ret0__ref];
}
}
NSString* _error = go_seq_readUTF8(&out_);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary *details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
go_seq_free(&in_);
go_seq_free(&out_);
return ([_error length] == 0);
}
- (double)Sum { - (double)Sum {
GoSeq in_ = {}; GoSeq in_ = {};
GoSeq out_ = {}; GoSeq out_ = {};