Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,41 @@ app.activateIgnoringOtherApps(true)

alert = ObjRuby::NSAlert.new
alert.messageText = "Hello world!"

alert.runModal
```

Subclasses of `ObjRuby::NSObject` can also be used for delegates such as NSApplicationDelegate.

``` ruby
require "obj_ruby"
require "obj_ruby/app_kit"

# NSApplicationDelegate
class AppDelegate < ObjRuby::NSObject
def applicationShouldTerminateAfterLastWindowClosed(_)
true
end
end

app = ObjRuby::NSApplication.sharedApplication
app.activationPolicy = ObjRuby::NSApplicationActivationPolicyRegular
app.delegate = AppDelegate.new

window = ObjRuby::NSWindow.alloc.initWithContentRect_styleMask_backing_defer(
ObjRuby::NSMakeRect(0, 0, 300, 200),
ObjRuby::NSTitledWindowMask | ObjRuby::NSWindowStyleMaskClosable,
ObjRuby::NSBackingStoreBuffered,
false
)
window.cascadeTopLeftFromPoint(ObjRuby::NSMakePoint(20, 20))
window.title = "Hello, from ObjRuby!"
window.makeKeyAndOrderFront(nil)

app.activateIgnoringOtherApps(true)
app.run
```

For more examples, see this projects [spec](https://github.com/keegnotrub/obj-ruby/tree/main/spec) folder.

## Credit
Expand Down
4 changes: 2 additions & 2 deletions ext/obj_ext/RIGSCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <dlfcn.h>
#include <ffi/ffi.h>

BOOL rb_objc_convert_to_objc(VALUE rb_val, void **data, size_t offset, const char *type);
BOOL rb_objc_convert_to_rb(void *data, size_t offset, const char *type, VALUE *rb_val_ptr);
void rb_objc_convert_to_objc(VALUE rb_val, void **data, size_t offset, const char *type);
void rb_objc_convert_to_rb(void *data, size_t offset, const char *type, VALUE *rb_val_ptr);

BOOL rb_objc_register_framework_from_objc(char *framework, const char *root);

Expand Down
Loading