Hey, I just want you to know that this is VERY VERY cool!!! Yours, GC On Sun, Aug 6, 2023 at 12:05 PM <[email protected]> wrote:
> I have solved the NSWindow initializer issue. I didn't realize I was > passing Swift's Foundation.NSRect and not the C version. Sill haven't > solved the issues regarding adding new ObjC classes to the runtime at > runtime through Swift. Any ideas here would be appreciated. > > The image below is an GNUStep app written in Swift. The Menu is from the > GORM file from the Terminal (I had to start somewhere!) > > [image: Screenshot 2023-08-06 at 10.54.06 AM.png] > > > On Aug 5, 2023, at 9:03 PM, [email protected] wrote: > > 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! > > > -- Gregory Casamento GNUstep Lead Developer / OLC, Principal Consultant http://www.gnustep.org - http://heronsperch.blogspot.com https://www.patreon.com/bePatron?u=352392 - Become a Patron https://www.openhub.net/languages/objective_c - OpenHub standings
