Re: C functions
Re: C functions
- Subject: Re: C functions
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sat, 19 Oct 2013 17:43:54 +0200
Le 19 oct. 2013 à 15:01, Uli Kusterer <email@hidden> a écrit :
> On 19 Oct 2013, at 01:17, Shane Stanley <email@hidden> wrote:
>> On 19 Oct 2013, at 3:15 AM, Uli Kusterer <email@hidden> wrote:
>>
>>> this is what you'd do if you wanted to make e.g. CoreFoundation APIs accessible to a scripting language
>>
>> That's along the lines of what I had in mind, although in this case for basic things like the trig functions in Math.h.
>
> So, is this supposed to just directly hand off some standard functions you decide to map into your library, like PHP exposes most of the standard C library? In that case I’d probably just write a little script that generates wrappers that translate between your language’s calling convention and the one of the C library, and enter them in a global variable with a struct that maps the plain-text name to the function pointer.
>
> Whether you actually want to regex-parse the headers (like I did here for my Hammer programming language: https://github.com/uliwitness/Forge/blob/master/headerimport.php) or whether you want to just hand-write a short, easily parsed list of the functions and their argument types is up to you. The latter requires less maintenance if you plan to only selectively import a few native calls, as regex-parsing of C/ObjC headers is rather optimistic and tends to break every couple of system releases.
>
To parse C/Obj-C/C++ headers, you can also use libclang which is design to do that. I used it to parse C header and generate boilerplate code some times ago, and it worked quite well with very few code to write on my side.
> If you, on the other hand, want to support creation of actual headers by users of your language and adding of new functions w/o recompiling, you’re prolly best off with a foreign function interface like libffi.
>
> Cheers,
> -- Uli Kusterer
> “The Witnesses of TeachText are everywhere...”
> http://stacksmith.org
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
-- Jean-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden