Multiple packages are already supported, but only as if each packages were bound in isolation. This CL lets a bound package refer to other bound packages in its exported functions, types and fields. In Java, the JNI class jclass and constructor jmethodID are exported so other packages can construct proxies of other packages' interfaces. In ObjC, the class @interface declarations are moved from the package .m file to its .h file to allow other packages to constructs its interface proxies. Add a supporting test package, secondpkg, and add Java and ObjC tests for the new cross package functionality. Also add simplepkg for testing corner cases where the generated Go file must not include its bound package. While we're here, stop generating Go proxy types for struct types; only Go interfaces can be implemented in the foreign language. Change-Id: Icbfa739c893703867d38a9100ed0928fbd7a660d Reviewed-on: https://go-review.googlesource.com/20575 Reviewed-by: David Crawshaw <crawshaw@golang.org>
175 lines
4.0 KiB
Plaintext
175 lines
4.0 KiB
Plaintext
// Objective-C API for talking to structs Go package.
|
|
// gobind -lang=objc structs
|
|
//
|
|
// File is generated by gobind. Do not edit.
|
|
|
|
#include <Foundation/Foundation.h>
|
|
#include "seq.h"
|
|
#include "_cgo_export.h"
|
|
#include "GoStructs.h"
|
|
|
|
static NSString* errDomain = @"go.structs";
|
|
|
|
@protocol goSeqRefInterface
|
|
-(GoSeqRef*) _ref;
|
|
@end
|
|
|
|
|
|
@implementation GoStructsS {
|
|
}
|
|
|
|
- (id)initWithRef:(id)ref {
|
|
self = [super init];
|
|
if (self) { __ref = ref; }
|
|
return self;
|
|
}
|
|
|
|
- (double)x {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
double r0 = proxystructs_S_X_Get(refnum);
|
|
double _r0 = (double)r0;
|
|
return _r0;
|
|
}
|
|
|
|
- (void)setX:(double)v {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
double _v = (double)v;
|
|
proxystructs_S_X_Set(refnum, _v);
|
|
}
|
|
|
|
- (double)y {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
double r0 = proxystructs_S_Y_Get(refnum);
|
|
double _r0 = (double)r0;
|
|
return _r0;
|
|
}
|
|
|
|
- (void)setY:(double)v {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
double _v = (double)v;
|
|
proxystructs_S_Y_Set(refnum, _v);
|
|
}
|
|
|
|
- (BOOL)identity:(GoStructsS**)ret0_ error:(NSError**)error {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
struct proxystructs_S_Identity_return res = proxystructs_S_Identity(refnum);
|
|
GoStructsS* _ret0_ = nil;
|
|
GoSeqRef* _ret0__ref = go_seq_from_refnum(res.r0);
|
|
if (_ret0__ref != NULL) {
|
|
_ret0_ = _ret0__ref.obj;
|
|
if (_ret0_ == nil) {
|
|
_ret0_ = [[GoStructsS alloc] initWithRef:_ret0__ref];
|
|
}
|
|
}
|
|
NSString *_error = go_seq_to_objc_string(res.r1);
|
|
*ret0_ = _ret0_;
|
|
if ([_error length] != 0 && error != nil) {
|
|
NSMutableDictionary* details = [NSMutableDictionary dictionary];
|
|
[details setValue:_error forKey:NSLocalizedDescriptionKey];
|
|
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
|
|
}
|
|
return ([_error length] == 0);
|
|
}
|
|
|
|
- (double)sum {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
double r0 = proxystructs_S_Sum(refnum);
|
|
double _ret0_ = (double)r0;
|
|
return _ret0_;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation GoStructsS2 {
|
|
}
|
|
|
|
- (id)initWithRef:(id)ref {
|
|
self = [super init];
|
|
if (self) { __ref = ref; }
|
|
return self;
|
|
}
|
|
|
|
- (void)m {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
proxystructs_S2_M(refnum);
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation GoStructsI {
|
|
}
|
|
|
|
- (id)initWithRef:(id)ref {
|
|
self = [super init];
|
|
if (self) { __ref = ref; }
|
|
return self;
|
|
}
|
|
|
|
- (void)m {
|
|
int32_t refnum = go_seq_go_to_refnum(self._ref);
|
|
proxystructs_I_M(refnum);
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
GoStructsS* GoStructsIdentity(GoStructsS* s) {
|
|
int32_t _s;
|
|
if ([(id<NSObject>)(s) isKindOfClass:[GoStructsS class]]) {
|
|
id<goSeqRefInterface> s_proxy = (id<goSeqRefInterface>)(s);
|
|
_s = go_seq_go_to_refnum(s_proxy._ref);
|
|
} else {
|
|
_s = go_seq_to_refnum(s);
|
|
}
|
|
int32_t r0 = proxystructs__Identity(_s);
|
|
GoStructsS* _ret0_ = nil;
|
|
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
|
|
if (_ret0__ref != NULL) {
|
|
_ret0_ = _ret0__ref.obj;
|
|
if (_ret0_ == nil) {
|
|
_ret0_ = [[GoStructsS alloc] initWithRef:_ret0__ref];
|
|
}
|
|
}
|
|
return _ret0_;
|
|
}
|
|
|
|
BOOL GoStructsIdentityWithError(GoStructsS* s, GoStructsS** ret0_, NSError** error) {
|
|
int32_t _s;
|
|
if ([(id<NSObject>)(s) isKindOfClass:[GoStructsS class]]) {
|
|
id<goSeqRefInterface> s_proxy = (id<goSeqRefInterface>)(s);
|
|
_s = go_seq_go_to_refnum(s_proxy._ref);
|
|
} else {
|
|
_s = go_seq_to_refnum(s);
|
|
}
|
|
struct proxystructs__IdentityWithError_return res = proxystructs__IdentityWithError(_s);
|
|
GoStructsS* _ret0_ = nil;
|
|
GoSeqRef* _ret0__ref = go_seq_from_refnum(res.r0);
|
|
if (_ret0__ref != NULL) {
|
|
_ret0_ = _ret0__ref.obj;
|
|
if (_ret0_ == nil) {
|
|
_ret0_ = [[GoStructsS alloc] initWithRef:_ret0__ref];
|
|
}
|
|
}
|
|
NSString *_error = go_seq_to_objc_string(res.r1);
|
|
*ret0_ = _ret0_;
|
|
if ([_error length] != 0 && error != nil) {
|
|
NSMutableDictionary* details = [NSMutableDictionary dictionary];
|
|
[details setValue:_error forKey:NSLocalizedDescriptionKey];
|
|
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
|
|
}
|
|
return ([_error length] == 0);
|
|
}
|
|
|
|
void cproxystructs_I_M(int32_t refnum) {
|
|
@autoreleasepool {
|
|
id<GoStructsI> o = go_seq_objc_from_refnum(refnum);
|
|
[o m];
|
|
}
|
|
}
|
|
|
|
__attribute__((constructor)) static void init() {
|
|
init_seq();
|
|
}
|