On Wed, 07 Jul 2004, [EMAIL PROTECTED] wrote:

> 3.  I have never done "function pointers" etc. in C except for some
> hacked-up cutting and pasting.  Does anyone know what the best way
> to, say, given the string name of a function to be able to call that
> function?  So the gui could do something like
> "gui_core_interface_call_core_function( "download_new", [parameter
> list])"

I think you want to know how to implement "gui_...call_core_function"?
If you want to use strings, you would need an array of value pair.

    #define STRINGIZE(a) #a
    #define STRINGED(a) STRINGIZE(a)
    #define ENTRY(a) {STRINGED(a), (int(*)())a }
    struct vp {
      const char *name;
      int (*fp)();
    } caller[] = {
      ENTRY(download_new),  
      ENTRY(upload_new),
      /* ... */
    };

...

   gui_core_interface_call_core_function(const char *name, ...)
   {
        /* match name and call function... */
        for(i = 0; i < NELEMENTS(caller); i++) {
            if(strcmp(caller[i].name, name)==0) {
                return caller[i].fp(/*var_args? */);
            }
        }
   }

Your parameters have to be consistent.  You could make a macro that
would do this, but you would always need to call with the likes of
"functionXXX".  Ie, not a variable pointing to a constant string.

Some platform have ways to shift the arguments.  This won't work with
all architectures, so you need var_args in all core functions.  An
idea that is probably revolting.  It would also be possible to write a
bunch of stubs through a script, but this is really starting to get
like an RPC as Richard mentioned.

There is no way to do this dynamically like in Java or something.  The
'C' code is compiled and there is no information about a symbol name.
You could look at "ELF" symbols/debug info, but that wouldn't be
portable at all.

fwiw,
Bill Pringlemeir.



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Gtk-gnutella-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/gtk-gnutella-devel

Reply via email to