I just wanted to update everyone on my progress and solicit some help if 
possible.

State of my progress: 
I've had a lot of success patching into GNUStep's libobjc2 C runtime from 
within Swift. I've been able to create NSWindows through Swift, call methods, 
et cetera. You can see my progress here 
https://github.com/austintatiousness/GNUStepSwiftBridge . This assumes that 
you're running this from within OnFlapp's GNUStep Desktop. 

Solution to objcSendMessage: 
Because Swift doesn't allow variable argument parameters, I had to create 
various versions of objcSendMessage (e.g forSwift_objcSendMessage1, 
forSwift_objcSendMessage2, forSwift_objcSendMessage3) to accommodate various 
number of arguments. 

Problem 1: NSWindow initWithContentRect:styleMask:backing:defer

1) I am having trouble with the NSWindow.initWith… functions. I am sure that it 
is because of the way that I am casting all the values from Swift into to the C 
implementation. Either I just don't understand how the casting between Swift 
and C works OR I am just using the wrong variables.  I include a C version of 
the NSRect struct in my project. 

let  nsWindowClass =  objc_getClass("NSWindow")
var allocatedObject = forSwift_objcSendMessage(&nsWindowClass!.pointee, 
sel_registerName("alloc"))

var styleMask: UInt64 = 1 + 2 + 4
var backingStoreType: UInt64 = 0
var deferr: UInt8 = 0
var rect = NSRect(x: 200, y: 200, width: 300, height: 300)

allocatedObject = forSwift_objcSendMessage4(&allocatedObject!.pointee, 
sel_registerName("initWithContentRect:styleMask:backing:defer:"), &rect, 
&styleMask, &backingStoreType, &deferr)

I've tried several times to change the various integer types from UInt64 to 
UInt8 to no avail. 

Problem 2: Registering new classes  with the runtime. 
This is the current state of the HelloWorld target: 

For reasons I cannot explain, I am able to allocate a new obj-c object with 
objc_allocateClassPair and then register it using objc_registerClassPair but 
when objc_getClass using the same class name that I registered, it returns nil.

Any help would be appreciated. I am currently unable to make progress on adding 
delegates with out being able to register new ObjC classes with the runtime. 

Thanks!

Reply via email to