Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/garettbass/oc

Macro magic for declaring/calling Objective-C APIs from C11 or C++. Preloads selectors, chooses the correct objc_msgSend to call per method/platform.
https://github.com/garettbass/oc

Last synced: 27 days ago
JSON representation

Macro magic for declaring/calling Objective-C APIs from C11 or C++. Preloads selectors, chooses the correct objc_msgSend to call per method/platform.

Awesome Lists containing this project

README

        

# OC - Easily Declare/Invoke Objective-C APIs from C11 or C++11

## Usage

```c
// Call class and instance methods:
NSWindow* const nswindow = oc_cls(NSWindow,new);
oc_obj(nswindow,NSWindow,setRestorable,false);
oc_obj(nswindow,NSWindow,setReleasedWhenClosed,false);
oc_obj(nswindow,NSWindow,setStyleMask,windowStyle);
oc_obj(nswindow,NSWindow,setFrame,windowRect,display,true);
oc_obj(nswindow,NSWindow,setIsVisible,true);
oc_obj(nswindow,NSWindow,center);
```

```c
// Swizzle methods:
oc_obj_swizzle(void,NSWindow,dealloc) {
printf("NSWindow.%s\n",(const char*)cmd);
imp(self, cmd);
}
```

```c
// Declare and implement classes:
oc_interface(
AppDelegate,
)

oc_implementation(
AppDelegate, NSObject,
obj(void,
applicationDidFinishLaunching,NSNotification*),
obj(NSApplicationTerminateReply,
applicationShouldTerminate,NSApplication*),
obj(void,
applicationWillTerminate,NSNotification*),
)

oc_method(
void,
AppDelegate,
applicationDidFinishLaunching,NSNotification*
) {
puts(__func__);
}

oc_method(
NSApplicationTerminateReply,
AppDelegate,
applicationShouldTerminate,NSApplication*
) {
puts(__func__);
app_quit();
return NSApplicationTerminateCancel;
}

oc_method(
void,
AppDelegate,
applicationWillTerminate,NSNotification*
) {
puts(__func__);
app_quit();
}
```