Professional Web Applications Themes

How call arbitrary MacOS APIs from my interpreter? - Mac Programming

Hi, I have written a little interpreter in C++. I'd like to allow my users to call arbitrary MacOS X APIs (Carbon, and later a Cocoa bridge). Users simply provide a prototype for the MacOS API call, specifying parameter types, name and framework, and I'd use CFBundleGetFunctionPointerForName() to look up the proper symbol. So far, so good, but how would I actually *call* this function. After all, I do not know the signature of the function until runtime. Can anyone point me at info on how to do that? There is apparently no way to do this in C++, and ...

  1. #1

    Default How call arbitrary MacOS APIs from my interpreter?

    Hi,

    I have written a little interpreter in C++. I'd like to allow my users
    to call arbitrary MacOS X APIs (Carbon, and later a Cocoa bridge).

    Users simply provide a prototype for the MacOS API call, specifying
    parameter types, name and framework, and I'd use
    CFBundleGetFunctionPointerForName() to look up the proper symbol. So
    far, so good, but how would I actually *call* this function. After all,
    I do not know the signature of the function until runtime.

    Can anyone point me at info on how to do that? There is apparently no
    way to do this in C++, and my knowledge of PowerPC assembler is zero...
    (Though I have academic knowledge of 68k asm).

    Thanks and Cheers,
    -- M. Uli Kusterer
    [url]http://www.zathras.de[/url]
    Uli Kusterer Guest

  2. #2

    Default Re: How call arbitrary MacOS APIs from my interpreter?

    In article <bf27ot$82a$1news.apple.com>,
    Peter Ammon <pa44cornell.edu> wrote:
    > One way is to use libffi, which is now part of gcc. (...) This is
    > probably the easiest way to go.
    >
    > You can also just implement it yourself, using assembly. It's not very
    > difficult in the general case. Basically, you load the parameters to
    > the function into the general purpose registers, starting at r3, and
    > then you bl (branch and link) to the function. When it returns, the
    > result is in r3.
    >
    >(...) You should use the "PowerPC calling conventions" section of
    > <file:///Developer/Doentation/DeveloperTools/MachORuntime/2rt_powerpc_abi/i
    > ndex.html>
    > as a reference if you decide to go this route.
    Thanks for the pointers, I'll check those out.

    Cheers,
    -- M. Uli Kusterer
    [url]http://www.zathras.de[/url]
    Uli Kusterer Guest

  3. #3

    Default Re: How call arbitrary MacOS APIs from my interpreter?

    In article <witness-FD0DE7.23130615072003news.t-online.com>,
    Uli Kusterer <witnesst-online.de> wrote:
    > I have written a little interpreter in C++. I'd like to allow my users
    >to call arbitrary MacOS X APIs (Carbon, and later a Cocoa bridge).
    >
    > Users simply provide a prototype for the MacOS API call, specifying
    >parameter types, name and framework, and I'd use
    >CFBundleGetFunctionPointerForName() to look up the proper symbol. So
    >far, so good, but how would I actually *call* this function. After all,
    >I do not know the signature of the function until runtime.
    >
    > Can anyone point me at info on how to do that?
    Calling a Carbon procedure without knowing how it's implemented
    isn't possible. In fact, the program may not even know the
    names of any procedures you might want to call.

    You can do it relatively easily for Cocoa, since you can call
    an arbitrary method for an arbitrary object supplying the
    method name as text. See

    file:///Developer/Doentation/Cocoa/TasksAndConcepts/ProgrammingTopics/DistrObjects/Tasks/invocations.html

    So you, the programmer, don't have to know anything about the
    object or method. You can find out information about this
    using NSMethodSignature .

    AppleScript Studio has a 'call method' instruction which does
    what you want: you supply the object, the method name and the
    parameters and it does the appropriate thing and returns the
    result.


    Simon Slavin Guest

  4. #4

    Default Re: How call arbitrary MacOS APIs from my interpreter?

    On Fri, 18 Jul 2003 [email]slavinshearsay.demon.co.uk[/email] wrote:
    > In article <witness-FD0DE7.23130615072003news.t-online.com>,
    > Uli Kusterer <witnesst-online.de> wrote:
    >
    > > I have written a little interpreter in C++. I'd like to allow my users
    > >to call arbitrary MacOS X APIs (Carbon, and later a Cocoa bridge).
    > >
    > > Users simply provide a prototype for the MacOS API call, specifying
    > >parameter types, name and framework, and I'd use
    > >CFBundleGetFunctionPointerForName() to look up the proper symbol. So
    > >far, so good, but how would I actually *call* this function. After all,
    > >I do not know the signature of the function until runtime.
    > >
    > > Can anyone point me at info on how to do that?
    >
    > Calling a Carbon procedure without knowing how it's implemented
    > isn't possible. In fact, the program may not even know the
    > names of any procedures you might want to call.
    >
    While you might not be able to do it in C, you should be able to do it
    with a bit of assembly. I'd guess the Apple's doentation on assembly
    language would tell you how to put parameters on the stack, get return values
    etc...

    Fred

    Frederick Cheung Guest

  5. #5

    Default Re: How call arbitrary MacOS APIs from my interpreter?

    In article
    <Pine.LNX.4.44.0307191410150.7662-100000kern.srcf.societies.cam.ac.uk>,
    Frederick Cheung <fglc2srcf.DUH.ucam.org> wrote:
    > > Calling a Carbon procedure without knowing how it's implemented
    > > isn't possible. In fact, the program may not even know the
    > > names of any procedures you might want to call.
    > >
    > While you might not be able to do it in C, you should be able to do it
    > with a bit of assembly. I'd guess the Apple's doentation on assembly
    > language would tell you how to put parameters on the stack, get return values
    > etc...
    Those are two different things.
    One topic is how to call an function given you know the ABI, calling
    convention and parameter format. That is certainly possible in Carbon,
    with / without assembler, etc. The emphasis, though, is on "UNKNOWN".

    The other topic is how an interpreter learns about the API. The usual C
    / C++ way is by declaring it in header files, (one) Objective-C / Java
    way is introspection / reflection (use an API to query what methods are
    available).
    Thomas Engelmeier Guest

  6. #6

    Default Re: How call arbitrary MacOS APIs from my interpreter?

    Thomas Engelmeier <jun03_nospamengelmeier.com> wrote:
    > Those are two different things.
    > One topic is how to call an function given you know the ABI, calling
    > convention and parameter format. That is certainly possible in Carbon,
    > with / without assembler, etc. The emphasis, though, is on "UNKNOWN".
    >
    > The other topic is how an interpreter learns about the API. The usual C
    > / C++ way is by declaring it in header files, (one) Objective-C / Java
    > way is introspection / reflection (use an API to query what methods are
    > available).
    If you read the original poster's message, you'll see that the "unknown" is known.

    "Users simply provide a prototype for the MacOS API call, specifying parameter typs, name and framework"

    What he wants are the calling conventions used so he can actually call a given function which will require some assembly.

    --
    [email]gbeggsCanada.com[/email] [url]http://www3.sympatico.ca/~gbeggs/[/url]
    Gerry Guest

Similar Threads

  1. Dir 8.5 - MacOS 9.2 projector in MacOS X Classic
    By davepla in forum Macromedia Director Basics
    Replies: 0
    Last Post: March 4th, 08:30 AM
  2. Free FTP clients for MacOS 7.5.5 .. MacOS 9 ?
    By Rolf Hemmerling in forum Mac Networking
    Replies: 3
    Last Post: August 12th, 01:39 AM
  3. Perl and C APIs
    By Gregski in forum PERL Miscellaneous
    Replies: 0
    Last Post: August 8th, 09:00 AM
  4. [PHP] Google APIs with PHP
    By Daniel Ke in forum PHP Development
    Replies: 1
    Last Post: July 31st, 12:35 PM
  5. Google APIs with PHP
    By Daniel Ke in forum PHP Development
    Replies: 0
    Last Post: July 31st, 04:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139