[swift-users] Fwd: Re: Binding Regular C Functions (Gtk, Cairo, etc.)

Gage Morgan gagemorgan at outlook.com
Mon Dec 7 21:39:32 CST 2015

Okey, so I see what they're trying to say, but what about functions from C that actually take input? For example, in Cairo, cairo_move_to() would not make the cut on its own. Matter of fact, it would take a surface in the form of a pointer and an x and y value. So we would have
cairo_surface_t *crcairo_move_to(cr, x, y);
among countless others. Is Swift able to pull this out of thin air, or do we have to take each individual function and convert it to Swift ourselves? I guess what I'm asking is: Is Swift able to understand something like
import CCairofunc cairo_line_to: Void(let cairo_t = MutableUnsafePointer(cr), x: Double, y: Double)
after I include just a header file and map it? The function draws a line on a surface. Assuming the syntax is correct, then you're telling me the process is just:
1) Map the cairo.h file to a system module named CCairo2) Include that in a file3) Convert any functions you've entered in C into a Swift format, no binding "workarounds" necessary like other lagnguages, and4) Swift recognizes you meant to use that function that is written specifically in C and is included in that header file mapped by CCairo. If Swift cannot automatically know that you meant to pull a function from a C header file, what must I do if it cannot?
I came here because I've read tutorials but am still confused on whether or not the CCairo module itself can just recognize a function without having to do more.

Sent from Outlook

On Mon, Dec 7, 2015 at 6:49 PM -0800, "Gage Morgan" <gagemorgan at outlook.com> wrote:

From: Gage Morgan <gagemorgan at outlook.com>
Sent: Monday, December 7, 2015 9:40 PM
Subject: Re: [swift-users] Binding Regular C Functions (Gtk, Cairo, etc.)
To: Mish Awadah <mawadah at apple.com>

              I read that. What I want to know is how to bind the functions themselves after creating a system package. How to use the c functions that got imported, if you will.

        Sent from     Outlook

      On Mon, Dec 7, 2015 at 6:39 PM -0800, "Mish Awadah"     <mawadah at apple.com> wrote:

         Please see the reference at    https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md
            - mish
                         On Dec 7, 2015, at 6:33 PM, Gage Morgan via swift-users <       swift-users at swift.org> wrote:
                       For any project: How is a C to Swift function binding created? I'd like to know how to import C functions to Swift. Once I can do this successfully, I'll be all set.

                  Sent from           Outlook
 swift-users mailing list
        swift-users at swift.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151208/69745afb/attachment.html>

More information about the swift-users mailing list