Open john-h-k opened 3 years ago
It's been several years since this issue was created, is there a possibility of this getting picked up? The lack of Objective-C support is blocking other projects like Silk.NET from binding to Apple APIs.
Perhaps a job for @Developer-Ecosystem-Engineering Ig not lol
Clang supports Objective-C and having the ability to generate code for it would be useful for many Apple-centric interop scenarios.
Work items
@protocol
s [current]@interface
s and@implementation
sSupport
@protocol
sProtocols are analogous to abstract classes/interfaces in C++/C#. They are a series of required methods and properties (getters and/or setters as in C#), and then optional methods and properties. Implementing types (called
@interface
s) must implement required attributes, but not optional attributes, and a special method (respondsToSelector
) is used to determine whether they are implemented. Due to this, publicly exposing all selectors is quite important.Protocol methods are called via the magic-method
objc_msgSend
(), which you cast to the prototype of the method you wish to call, but prepend 2 implicit parameters (self
of type `void, and
_cmdof type
SEL).
selfis the
thispointer for instance methods, or the class pointer (retrieved via
object_getClass("className")) for class (static) methods.
_cmdis the "selector" for the method, which is basically an opaque pointer handle that represents a method name (Obj-C does not support method overloading, but as parameter names are considered part of the method name, 2 methods with different parameter names are differently named, and this is reflected by the selector) and is used to identify the method you wish to call. Selectors are retrieved by calling
sel_registerName("selector"), where the selector has the format
methodName(for no params), or
methodName:param1:param2:param3` (you can remove param names but it can lead to ambiguities).* there are actually a couple of different forms of
objc_msgSend
for different types of return value, but the principle is the sameRoughly how it would work for C# is:
Changes to clangsharp
Requires adding