成员变量 类方法无法使用
ljh740 opened this issue · 1 comments
ljh740 commented
oc:
@interface RuntimeSon : RuntimeStub
@property (nonatomic,copy) NSString *test;
+ (instancetype)init2;
@end
codegen生成的代码
import 'dart:ffi';
import 'package:dart_native/dart_native.dart';
import 'package:dart_native_gen/dart_native_gen.dart';
import 'runtimestub.dart';
@native
class RuntimeSon extends RuntimeStub {
RuntimeSon([Class isa]) : super(Class('RuntimeSon'));
String get test => perform('test'.toSEL());
set test(String test) => perform('setTest:'.toSEL(), args: [test]);
static RuntimeSon init2() {
return Class('RuntimeSon').perform('init2'.toSEL(), args: []);
}
}
dart:
_clickMe() {
var test = RuntimeSon();
test.test = 'asdfafs';
}
_clickMeInit() {
var test = RuntimeSon.init2();
print(test);
}
第一个报错
flutter: Another exception was thrown: signature for [Pointer<Void>: address=0x60000241d070 setTest:] is NULL.
第二个报错
flutter: Another exception was thrown: type 'NSObject' is not a subtype of type 'RuntimeSon'
yulingtianxia commented
第一个问题我已经复现,原因是 class
传的有问题,下个版本会修复。目前可以手动修复,就是在调用 super
的时候,传入的 isa
指针前面需要优先用传入的 isa
, 也就是加上 isa ??
:
RuntimeSon([Class isa]) : super(isa ?? Class('RuntimeSon'));
RuntimeStub([Class isa]) : super(isa ?? Class('RuntimeStub'));
第二个问题是 codegen 的 bug,已经在 unittest 分支修复,还没合入 master。可以手动改下生成的 dart 代码如下:
// 需要加这行,下个版本 codegen 会自动生成
RuntimeSon.fromPointer(Pointer<Void> ptr) : super.fromPointer(ptr);
static RuntimeSon init2() {
Pointer<Void> result =
Class('RuntimeSon').perform(SEL('init2'), args: [], decodeRetVal: false);
return RuntimeSon.fromPointer(result);
}