diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-28 18:30:06 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-28 18:30:06 -0500 |
| commit | 8af591388f3bc0295ba196135452e29e845925a8 (patch) | |
| tree | 72847d5b5a96f5608b6359a33bc2755a7d336bfc /darwintest/objc_darwin.h | |
| parent | e4339d3c49453794dee1b9f0f3a48bd7ce8cae6f (diff) | |
Split most of the objc_msgSend() wrappers into a C header file for convenience. The NSRect functions require special handling because of Apple stupidities that will be discussed when I get to that.
Diffstat (limited to 'darwintest/objc_darwin.h')
| -rw-r--r-- | darwintest/objc_darwin.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/darwintest/objc_darwin.h b/darwintest/objc_darwin.h new file mode 100644 index 0000000..85bf0b4 --- /dev/null +++ b/darwintest/objc_darwin.h @@ -0,0 +1,61 @@ +/* 28 february 2014 */ + +/* +This includes all Objective-C runtime headers for convenience. It also creates wrappers around objc_msgSend() out of necessity. + +cgo doesn't support calling variable argument list C functions, so objc_msgSend() cannot be called directly. + +Furthermore, Objective-C selectors work by basically sending the arguments to objc_msgSend() verbatim across the wire. This basically means we're stuck making wrapper functions for every possible argument list. What fun! + +The format should be self-explanatory. +*/ + +#include <objc/message.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +/* TODO this HAS to be unsafe, but <objc/NSObjCRuntime.h> not found?! */ +typedef unsigned long NSUInteger; + +inline id objc_msgSend_noargs(id obj, SEL sel) +{ + return objc_msgSend(obj, sel); +} + +#define m1(name, type1) \ + inline id objc_msgSend_ ## name (id obj, SEL sel, type1 a) \ + { \ + return objc_msgSend(obj, sel, a); \ + } + +#define m2(name, type1, type2) \ + inline id objc_msgSend_ ## name (id obj, SEL sel, type1 a, type2 b) \ + { \ + return objc_msgSend(obj, sel, a, b); \ + } + +#define m3(name, type1, type2, type3) \ + inline id objc_msgSend_ ## name (id obj, SEL sel, type1 a, type2 b, type3 c) \ + { \ + return objc_msgSend(obj, sel, a, b, c); \ + } + +#define m4(name, type1, type2, type3, type4) \ + inline id objc_msgSend_ ## name (id obj, SEL sel, type1 a, type2 b, type3 c, type4 d) \ + { \ + return objc_msgSend(obj, sel, a, b, c, d); \ + } + +m1(str, char *) /* TODO Go string? */ +m1(id, id) +/* TODO NSRect */ +m1(sel, SEL) +m1(uint, NSUInteger) + +m2(id_id, id, id) + +m3(id_id_id, id, id, id) +m3(sel_id_bool, SEL, id, BOOL) + +/* TODO NSRect */ +m4(id_sel_id_id, id, SEL, id, id) |
