Need Help with C-to-Swift (finally)

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.

I'll open a ticket to ensure swift build warns for this in future.

···

On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:

mgage@mgage:~/swift-cairo-bindings/test$ swift build -v
/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.

I'll have to test this out myself. Can't for a few hours at least.

In the mean time try `swift build -v` for some more information.

On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:

Cloning Packages/CCairo
Cloning Packages/Cairo
Compiling Swift Module 'Cairo' (1 sources)
Linking Executable: .build/debug/Cairo
Compiling Swift Module 'test' (1 sources)
Linking Executable: .build/debug/test
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.

Here's the bits for the actual Cairo module (wrappings, etc.) and all:
cairo-main.swift · GitHub

And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:
test-main.swift · GitHub

I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.

To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?

Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what I'm getting:

/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'
let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)
              ^~~~~ ~~~~~~~
<unknown>:0: error: build had 1 command failures

So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)

Cairo.Cairo should work fine.

On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile

On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:

But yes, a full wrapper would transparently handle getting and setting.

- Harlan

···

On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

···

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users

If they're not the same name, you don't need Cairo.Surface, just Surface.

···

Sent from my iPhone

On Dec 11, 2015, at 9:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what I'm getting:

/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'
let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)
              ^~~~~ ~~~~~~~
<unknown>:0: error: build had 1 command failures

So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)

Cairo.Cairo should work fine.

On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile

On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.

···

To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Right up ahead lol

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:42:03 -0800
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

If you could publish your sources on GitHub or somewhere similar we could probably be more help.
On Dec 11, 2015, at 6:21 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

I'm in the process of uploading the bits to GitHub, so I can push them over if anything else happens.

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.
I'll open a ticket to ensure swift build warns for this in future.
On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.
I'll open a ticket to ensure swift build warns for this in future.
On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

···

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)

Cairo.Cairo should work fine.

···

On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile <Bing;

On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com <mailto:harlan@harlanhaskins.com>> wrote:

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com <mailto:gagemorgan@outlook.com>> wrote:

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 failures
swift-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@harlanhaskins.com <mailto:harlan@harlanhaskins.com>
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com <mailto:gagemorgan@outlook.com>; swift-users@swift.org <mailto:swift-users@swift.org>
To: jackl@apple.com <mailto:jackl@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@apple.com <mailto:jackl@apple.com>> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@swift.org <mailto:swift-users@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@harlanhaskins.com <mailto:harlan@harlanhaskins.com>
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com <mailto:kwame.bryan@gmail.com>; swift-users@swift.org <mailto:swift-users@swift.org>
To: gagemorgan@outlook.com <mailto:gagemorgan@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@outlook.com <mailto:gagemorgan@outlook.com>> wrote:

Harlan,

I read on cairographics.org <http://cairographics.org/&gt; 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 <Bing;

On Fri, Dec 11, 2015 at 2:00 PM -0800, "Gage Morgan via swift-users" <swift-users@swift.org <mailto:swift-users@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 <Bing;

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@swift.org <mailto:swift-users@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 <Bing;

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@gmail.com <mailto:kwame.bryan@gmail.com>> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

Gotta make sure to make a git tag

git tag 1.0.0
git push --tags

···

Sent from my iPhone

On Dec 11, 2015, at 10:29 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.

I'll open a ticket to ensure swift build warns for this in future.

On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:

mgage@mgage:~/swift-cairo-bindings/test$ swift build -v
/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.

I'll have to test this out myself. Can't for a few hours at least.

In the mean time try `swift build -v` for some more information.

On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:

Cloning Packages/CCairo
Cloning Packages/Cairo
Compiling Swift Module 'Cairo' (1 sources)
Linking Executable: .build/debug/Cairo
Compiling Swift Module 'test' (1 sources)
Linking Executable: .build/debug/test
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.

Here's the bits for the actual Cairo module (wrappings, etc.) and all:
cairo-main.swift · GitHub

And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:
test-main.swift · GitHub

I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.

To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?

Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what I'm getting:

/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'
let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)
              ^~~~~ ~~~~~~~
<unknown>:0: error: build had 1 command failures

So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)

Cairo.Cairo should work fine.

On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile

On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Just when I think I make a breakthrough...Cairo and CCairo build, but this test file separates methods from wrappers still won't:
Compiling Swift Module 'test' (1 sources)/home/mgage/swift-cairo-bindings/test/test.swift:4:1: error: expressions are not allowed at the top levelsurface.scale(10.0, y: 10.0)^/home/mgage/swift-cairo-bindings/test/test.swift:5:1: error: expressions are not allowed at the top levelsurface.moveTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:6:1: error: expressions are not allowed at the top levelsurface.lineTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:7:1: error: expressions are not allowed at the top levelsurface.moveTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:8:1: error: expressions are not allowed at the top levelsurface.lineTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:9:1: error: expressions are not allowed at the top levelsurface.moveTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:10:1: error: expressions are not allowed at the top levelsurface.lineTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:11:1: error: expressions are not allowed at the top levelsurface.setLineWidth(0.1)^/home/mgage/swift-cairo-bindings/test/test.swift:12:1: error: expressions are not allowed at the top levelsurface.stroke()^/home/mgage/swift-cairo-bindings/test/test.swift:13:1: error: expressions are not allowed at the top levelsurface.surfaceWriteToPNG("boobs.png")^/home/mgage/swift-cairo-bindings/test/test.swift:3:15: error: use of unresolved identifier 'Surface'let surface = Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~~~<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
What is this "top level" thing? Not the first time I've seen it.

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:30:25 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta make sure to make a git tag
git tag 1.0.0git push --tags

Sent from my iPhone
On Dec 11, 2015, at 10:29 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.
I'll open a ticket to ensure swift build warns for this in future.
On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Gotta rename test.swift to main.swift, otherwise it'll try to compile it as a module.

This seems to be unintuitive -- we should probably file some structural bug reports to make this process more straightforward.

···

Sent from my iPhone

On Dec 11, 2015, at 10:36 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Just when I think I make a breakthrough...Cairo and CCairo build, but this test file separates methods from wrappers still won't:

Compiling Swift Module 'test' (1 sources)
/home/mgage/swift-cairo-bindings/test/test.swift:4:1: error: expressions are not allowed at the top level
surface.scale(10.0, y: 10.0)
^
/home/mgage/swift-cairo-bindings/test/test.swift:5:1: error: expressions are not allowed at the top level
surface.moveTo(29.0, y: 14.7)
^
/home/mgage/swift-cairo-bindings/test/test.swift:6:1: error: expressions are not allowed at the top level
surface.lineTo(37.6, y: 13.0)
^
/home/mgage/swift-cairo-bindings/test/test.swift:7:1: error: expressions are not allowed at the top level
surface.moveTo(37.6, y: 13.0)
^
/home/mgage/swift-cairo-bindings/test/test.swift:8:1: error: expressions are not allowed at the top level
surface.lineTo(30.4, y: 22.2)
^
/home/mgage/swift-cairo-bindings/test/test.swift:9:1: error: expressions are not allowed at the top level
surface.moveTo(30.4, y: 22.2)
^
/home/mgage/swift-cairo-bindings/test/test.swift:10:1: error: expressions are not allowed at the top level
surface.lineTo(29.0, y: 14.7)
^
/home/mgage/swift-cairo-bindings/test/test.swift:11:1: error: expressions are not allowed at the top level
surface.setLineWidth(0.1)
^
/home/mgage/swift-cairo-bindings/test/test.swift:12:1: error: expressions are not allowed at the top level
surface.stroke()
^
/home/mgage/swift-cairo-bindings/test/test.swift:13:1: error: expressions are not allowed at the top level
surface.surfaceWriteToPNG("boobs.png")
^
/home/mgage/swift-cairo-bindings/test/test.swift:3:15: error: use of unresolved identifier 'Surface'
let surface = Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)
              ^~~~~~~
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

What is this "top level" thing? Not the first time I've seen it.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:30:25 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta make sure to make a git tag

git tag 1.0.0
git push --tags

Sent from my iPhone

On Dec 11, 2015, at 10:29 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.

I'll open a ticket to ensure swift build warns for this in future.

On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:

mgage@mgage:~/swift-cairo-bindings/test$ swift build -v
/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.

I'll have to test this out myself. Can't for a few hours at least.

In the mean time try `swift build -v` for some more information.

On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:

Cloning Packages/CCairo
Cloning Packages/Cairo
Compiling Swift Module 'Cairo' (1 sources)
Linking Executable: .build/debug/Cairo
Compiling Swift Module 'test' (1 sources)
Linking Executable: .build/debug/test
/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'
/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]

I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.

Here's the bits for the actual Cairo module (wrappings, etc.) and all:
cairo-main.swift · GitHub

And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:
test-main.swift · GitHub

I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.

To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?

Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what I'm getting:

/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'
let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410)
              ^~~~~ ~~~~~~~
<unknown>:0: error: build had 1 command failures

So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)

Cairo.Cairo should work fine.

On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile

On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?

If Cairo is the module name, you're trying to instantiate the module.

- Harlan

On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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 failures
swift-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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@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@apple.com> wrote:

For getter-setter pairs like `setLineWidth`, you might consider turning them into properties:

cairo.setLineWidth(0.1) // old
cairo.lineWidth = 0.1 // new

On Dec 11, 2015, at 4:22 PM, Gage Morgan via swift-users <swift-users@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@gmail.com> wrote:

Tutorial on the subject. http://chris.eidhof.nl/posts/swift-c-interop.html

Regards
Kwame

<Mail Attachment.txt><Mail Attachment.txt>

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Yes, we seem to have uncovered some....uhhhhh.....difficulties.
Was anyone else aware that stuff like this is a wild-goose chase until now?

···

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:38:42 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta rename test.swift to main.swift, otherwise it'll try to compile it as a module.
This seems to be unintuitive -- we should probably file some structural bug reports to make this process more straightforward.

Sent from my iPhone
On Dec 11, 2015, at 10:36 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Just when I think I make a breakthrough...Cairo and CCairo build, but this test file separates methods from wrappers still won't:
Compiling Swift Module 'test' (1 sources)/home/mgage/swift-cairo-bindings/test/test.swift:4:1: error: expressions are not allowed at the top levelsurface.scale(10.0, y: 10.0)^/home/mgage/swift-cairo-bindings/test/test.swift:5:1: error: expressions are not allowed at the top levelsurface.moveTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:6:1: error: expressions are not allowed at the top levelsurface.lineTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:7:1: error: expressions are not allowed at the top levelsurface.moveTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:8:1: error: expressions are not allowed at the top levelsurface.lineTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:9:1: error: expressions are not allowed at the top levelsurface.moveTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:10:1: error: expressions are not allowed at the top levelsurface.lineTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:11:1: error: expressions are not allowed at the top levelsurface.setLineWidth(0.1)^/home/mgage/swift-cairo-bindings/test/test.swift:12:1: error: expressions are not allowed at the top levelsurface.stroke()^/home/mgage/swift-cairo-bindings/test/test.swift:13:1: error: expressions are not allowed at the top levelsurface.surfaceWriteToPNG("boobs.png")^/home/mgage/swift-cairo-bindings/test/test.swift:3:15: error: use of unresolved identifier 'Surface'let surface = Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~~~<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
What is this "top level" thing? Not the first time I've seen it.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:30:25 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta make sure to make a git tag
git tag 1.0.0git push --tags

Sent from my iPhone
On Dec 11, 2015, at 10:29 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.
I'll open a ticket to ensure swift build warns for this in future.
On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Okay, so test.swift is now main.swift, which outputs a much shorter but not better:
Compiling Swift Module 'test' (1 sources)/home/mgage/swift-cairo-bindings/test/main.swift:3:15: error: use of unresolved identifier 'Surface'let surface = Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~~~<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
Compilers and debuggers these days...Subject: Re: [swift-users] Need Help with C-to-Swift (finally)

···

From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:38:42 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta rename test.swift to main.swift, otherwise it'll try to compile it as a module.
This seems to be unintuitive -- we should probably file some structural bug reports to make this process more straightforward.

Sent from my iPhone
On Dec 11, 2015, at 10:36 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Just when I think I make a breakthrough...Cairo and CCairo build, but this test file separates methods from wrappers still won't:
Compiling Swift Module 'test' (1 sources)/home/mgage/swift-cairo-bindings/test/test.swift:4:1: error: expressions are not allowed at the top levelsurface.scale(10.0, y: 10.0)^/home/mgage/swift-cairo-bindings/test/test.swift:5:1: error: expressions are not allowed at the top levelsurface.moveTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:6:1: error: expressions are not allowed at the top levelsurface.lineTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:7:1: error: expressions are not allowed at the top levelsurface.moveTo(37.6, y: 13.0)^/home/mgage/swift-cairo-bindings/test/test.swift:8:1: error: expressions are not allowed at the top levelsurface.lineTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:9:1: error: expressions are not allowed at the top levelsurface.moveTo(30.4, y: 22.2)^/home/mgage/swift-cairo-bindings/test/test.swift:10:1: error: expressions are not allowed at the top levelsurface.lineTo(29.0, y: 14.7)^/home/mgage/swift-cairo-bindings/test/test.swift:11:1: error: expressions are not allowed at the top levelsurface.setLineWidth(0.1)^/home/mgage/swift-cairo-bindings/test/test.swift:12:1: error: expressions are not allowed at the top levelsurface.stroke()^/home/mgage/swift-cairo-bindings/test/test.swift:13:1: error: expressions are not allowed at the top levelsurface.surfaceWriteToPNG("boobs.png")^/home/mgage/swift-cairo-bindings/test/test.swift:3:15: error: use of unresolved identifier 'Surface'let surface = Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~~~<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
What is this "top level" thing? Not the first time I've seen it.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 22:30:25 -0500
CC: max.howell@apple.com; jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Gotta make sure to make a git tag
git tag 1.0.0git push --tags

Sent from my iPhone
On Dec 11, 2015, at 10:29 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Okay, so I've gone in and noticed that yes, it does create a library. How do I use that? Dependency graph won't check out for some strange reason.

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 19:02:41 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

Your Cairo module is an executable and not a library. Don't call files main.swift for libraries.
I'll open a ticket to ensure swift build warns for this in future.
On Dec 11, 2015, at 6:54 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

Here's what is inhibited when using swift build -v:
mgage@mgage:~/swift-cairo-bindings/test$ swift build -v/home/mgage/Downloads/swift/usr/bin/swiftc -o /home/mgage/swift-cairo-bindings/test/.build/debug/test /home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o -g -L/usr/local/lib/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-v", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I'm going to attempt to create a repo, but GitHub and I don't always get along ;)

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: max.howell@apple.com
Date: Fri, 11 Dec 2015 18:51:09 -0800
CC: jackl@apple.com; swift-users@swift.org; harlan@harlanhaskins.com
To: gagemorgan@outlook.com

The link failure is for the constructor for your Cairo class.
I'll have to test this out myself. Can't for a few hours at least.
In the mean time try `swift build -v` for some more information.
On Dec 11, 2015, at 6:42 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:

I have no idea what happened here, but:
Cloning Packages/CCairoCloning Packages/CairoCompiling Swift Module 'Cairo' (1 sources)Linking Executable: .build/debug/CairoCompiling Swift Module 'test' (1 sources)Linking Executable: .build/debug/test/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/main.swift.o: In function `main':/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TMaC5Cairo7Surface'/home/mgage/swift-cairo-bindings/test/main.swift:4: undefined reference to `_TFC5Cairo7SurfaceCfT6formatVSC13_cairo_format5widthSi6heightSi_S0_'clang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: build had 1 command failuresswift-build: exit(1): ["/home/mgage/Downloads/swift/usr/bin/swift-build-tool", "-f", "/home/mgage/swift-cairo-bindings/test/.build/debug/test.o/llbuild.yaml"]
I've made everything public, and I think the initializer needs to be public or something like that. That said, I have no idea what I need to do for this to work. Deinit doesn't seem to want to be public, so leaving that alone. I need to know why the reference to Surface won't come up.
Here's the bits for the actual Cairo module (wrappings, etc.) and all:cairo-main.swift · GitHub
And this is the one in the "test" directory where I'm trying to get the methods in the above file to work without complaint outside of the directory:test-main.swift · GitHub
I'm hoping someone can tell me what I'm doing wrong, because I'm trying to do whatever possible. Also, I did upgrade the Swift components earlier when released.
To: jackl@apple.com
Date: Fri, 11 Dec 2015 21:21:06 -0500
CC: swift-users@swift.org
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: swift-users@swift.org

I'm going to. Now, does this mean anything labelled func inside the struct needs tacked on as well?

Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: jackl@apple.com
Date: Fri, 11 Dec 2015 18:19:55 -0800
CC: harlan@harlanhaskins.com; swift-users@swift.org
To: gagemorgan@outlook.com

Did you make the class and its methods public?
Jack
On Dec 11, 2015, at 6:16 PM, Gage Morgan <gagemorgan@outlook.com> wrote:Here's what I'm getting:
/home/mgage/swift-cairo-bindings/test/main.swift:4:15: error: module 'Cairo' has no member named 'Surface'let surface = Cairo.Surface(format: CAIRO_FORMAT_ARGB32, width: 421, height: 410) ^~~~~ ~~~~~~~<unknown>:0: error: build had 1 command failures
So what I'm trying to do is to put all wrappings in a separate module named Cairo. Then, I want to use those methods outside of the module named Cairo. I renamed the class to Surface and fixed all references, but for some reason it keeps saying something about Surface not present. I need to look into whether a git repo may be needed.
Subject: Re: [swift-users] Need Help with C-to-Swift (finally)
From: harlan@harlanhaskins.com
Date: Fri, 11 Dec 2015 20:31:20 -0500
CC: jackl@apple.com; swift-users@swift.org
To: gagemorgan@outlook.com

Nope, but you’ll need a way to specify the class inside the module (the fully-qualified type name)
Cairo.Cairo should work fine.
On Dec 11, 2015, at 8:14 PM, Gage Morgan <gagemorgan@outlook.com> wrote:The module is Cairo. Do I need to change something (I'm assuming by struct you mean the name of the class containing wrappings). The class is named Cairo as well. Could renaming the module to ModCairo fix this?

Sent from Outlook Mobile
On Fri, Dec 11, 2015 at 5:11 PM -0800, "Harlan Haskins" <harlan@harlanhaskins.com> wrote:

Is your struct named Cairo or Surface?
If Cairo is the module name, you're trying to instantiate the module.

- Harlan
On Dec 11, 2015, at 7:55 PM, Gage Morgan <gagemorgan@outlook.com> wrote:

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@harlanhaskins.com
Date: Fri, 11 Dec 2015 19:35:46 -0500
CC: gagemorgan@outlook.com; swift-users@swift.org
To: jackl@apple.com

I considered that but couldn't find a cairo_get_font_scale function quickly to complement the setter :sweat_smile:
But yes, a full wrapper would transparently handle getting and setting.

- Harlan
On Dec 11, 2015, at 7:28 PM, Jack Lawrence <jackl@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@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@harlanhaskins.com
Date: Fri, 11 Dec 2015 17:21:38 -0500
CC: kwame.bryan@gmail.com; swift-users@swift.org
To: gagemorgan@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@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@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@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@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@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users
                 
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users