discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift calling into GNUStep Progress


From: M A
Subject: Re: Swift calling into GNUStep Progress
Date: Mon, 7 Aug 2023 13:57:39 -0400

A to do list would be a great edition to this project's website.

One thing I would add it making a program that can wrap an Objective-c class 
around Swift code. There are just too many classes and methods to do it all by 
hand.

> On Aug 7, 2023, at 1:51 PM, Gregory Casamento <greg.casamento@gmail.com> 
> wrote:
> 
> I am extremely impressed!!!  This is great!  Please let me know if I can help 
> in any way.
> 
> GC
> 
> On Mon, Aug 7, 2023 at 10:35 AM <dr_clow@me.com> wrote:
> Gregory, 
> 
> Thank you. I over last night, I was able to solve almost all the issues with 
> calling into GNUStep's AppKit and Foundation. I've been able to set up 
> buttons that respond to selectors, create objects at runtime and register 
> them with the runtime. Right now, I am working on generalizing a sort of 
> "Smart" version of obj_msgSend that allows me to not have to write a separate 
> version of that handles each type parameters. As it is now, the only way I am 
> getting it to work is to make a version of objc_msgSend that explicitly 
> takes, for example, an NSRect, or id. 
> 
> This is probably because I just don't fully understand how pointers work in 
> Swift. If anyone has any idea of how we can generalize the function, I would 
> greatly appreciate it. Thanks!
> 
> Below is a screen shot of a working app written in Swift. The button does 
> work and does open the other window. It's pretty cool. You can see the code 
> on my GitHub. It's messy still.  
> 
> 
> <Image 8-7-23 at 9.33 AM.jpeg>
> 
>> On Aug 6, 2023, at 7:59 PM, Gregory Casamento <greg.casamento@gmail.com> 
>> wrote:
>> 
>> Hey, I just want you to know that this is VERY VERY cool!!!  Yours, GC
>> 
>> On Sun, Aug 6, 2023 at 12:05 PM <dr_clow@me.com> 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!)
>> 
>> <Screenshot 2023-08-06 at 10.54.06 AM.png>
>> 
>> 
>>> On Aug 5, 2023, at 9:03 PM, dr_clow@me.com 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
> 
> 
> 
> -- 
> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]