[swift-users] Need Help with C-to-Swift (finally)
Gage Morgan
gagemorgan at outlook.com
Fri Dec 11 18:55:53 CST 2015
How would you use things like cairo.moveTo() outside of the wrapping file? I've gone as far as writing a module named "Cairo," taking the methods as mentioned above out, and moving them to their own directory "tests." I have added "Cairo" as a dependency for "tests," but there appears to be something wrong when I try to call:let cairo = Cairo(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)Why can I not call Cairo()? The error:Compiling Swift Module 'test' (1 sources)/home/mgage/swift-cairo-bindings/test/main.swift:4:18: error: cannot call value of non-function type 'module<Cairo>'let cairo = Cairo(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ~~~~~^<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I don't know whether or not I want to translate methods into straight-up properties yet.Thanks, support here has been great so far. Cheers!--MGage--
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan at harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan at outlook.com; swift-users at swift.org
To: jackl at apple.com
I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter 😅
But yes, a full wrapper would transparently handle getting and setting.
- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl at apple.com> wrote:
For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:
cairo.setLineWidth(0.1) // oldcairo.lineWidth = 0.1 // new
On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users at swift.org> wrote:Harlan,
The answer is yes. I even managed to get a couple you didn't list on my own:
let cairo = Cairo(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)cairo.scale(10.0, y: 10.0)cairo.moveTo(29.0, y: 14.7)cairo.lineTo(37.6, y: 13.0)cairo.moveTo(37.6, y: 13.0)cairo.lineTo(30.4, y: 22.2)cairo.moveTo(30.4, y: 22.2)cairo.lineTo(29.0, y: 14.7)cairo.setLineWidth(0.1)cairo.stroke()cairo.surfaceWriteToPNG("boobs.png")
Swift is both really neat and really frustrating when learning it.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan at harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan at gmail.com; swift-users at swift.org
To: gagemorgan at outlook.com
Gage,
Sorry, I just got back from class.
I’ll respond in line!
On Dec 11, 2015, at 5:09 PM, Gage Morgan <gagemorgan at outlook.com> wrote:Harlan,
I read on cairographics.org about bindings awhile back. I think they want cairo, not surface, so we would have something like:
let cairo = Surface(format: CAIRO_FORMAT_ARGB32, width: 240, height: 80)cairo.setFontFace("serif", weight: CAIRO_FONT_WEIGHT_BOLD)cairo.setFontSize(32.0)cairo.setSourceRGB(0.0, g: 0.0, b: 1.0)cairo.moveTo(x: 10, y: 50)cairo.showText("Hello, World!")cairo.writeToPNG("hello.png")
Would this work the same as before without "surface" but instead "cairo”?
Absolutely! That’s just a variable name — it could be called ‘puppies’, though that’s not very readable.
Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 2:00 PM -0800, "Gage Morgan via swift-users" <swift-users at swift.org> wrote:
I went and looked at it, and even now it looks like I want to take every function I've used in Cairo and translate it to Swift. Swift is such a...simple language compared to everything else. That being said, as a result of the specs, it is also much more verbose in terms of writing the code. Compared to other languages, it is written out instead of shoved onto a few lines.
Is there a way to import modules into other modules? Because it looks like a weekend project that will eventually get posted by myself at http://github.com/Christoffen-Corporation.
Sent from Outlook Mobile
I’d recommend having a look at the Swift package manager example again — https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md
There’s an example of using those modules together.
On Fri, Dec 11, 2015 at 1:52 PM -0800, "Gage Morgan via swift-users" <swift-users at swift.org> wrote:
I meant the code posted in the Gist link above. I don't know jack squat about qsort. I'm hoping that if I can reverse-engineer code already produced, I can apply it to other parts of Cairo.
Sent from Outlook Mobile
I’ll go ahead and comment it, but I think it’s simplistic enough that it should be readable with a grasp of some Swift concepts. Perhaps it’s a good idea to look through The Swift Programming Language to figure out some of the constructs I used — they’re fairly basic constructs.
On Fri, Dec 11, 2015 at 1:34 PM -0800, "Kwame Bryan"<kwame.bryan at gmail.com> wrote:
Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html
RegardsKwame<Mail Attachment.txt><Mail Attachment.txt>
_______________________________________________swift-users mailing listswift-users at swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151211/2d1769ea/attachment.html>
More information about the swift-users
mailing list