-
Notifications
You must be signed in to change notification settings - Fork 193
/
objc.h
57 lines (45 loc) · 1.4 KB
/
objc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef __OBJC_H_
#define __OBJC_H_
#include "bs.h"
struct rb_objc_method_sig {
const char *types;
unsigned int argc;
};
bool rb_objc_fill_sig(VALUE recv, Class klass, SEL sel, struct rb_objc_method_sig *sig, bs_element_method_t *bs_method);
VALUE rb_objc_call(VALUE recv, SEL sel, int argc, VALUE *argv);
VALUE rb_objc_call2(VALUE recv, VALUE klass, SEL sel, IMP imp,
struct rb_objc_method_sig *sig, bs_element_method_t *bs_method, int argc,
VALUE *argv);
void rb_objc_define_kvo_setter(VALUE klass, ID mid);
void rb_objc_change_ruby_method_signature(VALUE mod, ID mid, VALUE sig);
static inline void
rb_objc_install_method(Class klass, SEL sel, IMP imp)
{
Method method, method2;
method = class_getInstanceMethod(klass, sel);
assert(method != NULL);
method2 = class_getInstanceMethod((Class)RCLASS_SUPER(klass), sel);
if (method == method2) {
assert(class_addMethod(klass, sel, imp, method_getTypeEncoding(method)));
}
else {
method_setImplementation(method, imp);
}
}
static inline void
rb_objc_install_method2(Class klass, const char *selname, IMP imp)
{
rb_objc_install_method(klass, sel_registerName(selname), imp);
}
static inline bool
rb_objc_is_kind_of(id object, Class klass)
{
Class cls;
for (cls = *(Class *)object; cls != NULL; cls = class_getSuperclass(cls)) {
if (cls == klass) {
return true;
}
}
return false;
}
#endif /* __OBJC_H_ */