Re: Plugins as game data



On 2007-12-17 23:33:18, konijn_ <konijn@xxxxxxxxx> wrote:

On 2007-12-17 22:37:03, Kenneth 'Bessarion' Boyd wrote:

On 2007-12-17 22:02:54, konijn_ wrote:

On Dec 17, 3:19 pm, jice wrote:

You don't have to use a global variable to pass parameters to a
dynamically linked function.
Once you have the address of the function, cast it using a function
pointer :

// declaration of the function pointer
void (*addDamageTypePtr)(char *type, char *value);

// address of the function retrieved from the dll (see my previous
post)
void * myFunctionAddress =3D ...

// cast your void * address into the right function pointer
addDamageTypePtr =3D myFunctionAddress;

// then use it as a standard function
addDamageTypePtr("Acid","10d4");

But, splutter ;)

That would mean that my parsing routine would need to know about
addDamageType which I want to avoid.
In my design, only the script/module and the called function need to
know which parameters are used, the parser just parses parameters and
calls functions.

Assuming that all data types involved in the function call are ...-friendly, try
casting to

void (*omnifunc_type)(....)

Typo fix: void (*omnifunc_type)(...)

This requires C calling convention for everything, but should let the parser be
clueless about the actual function type.

Wow, that flew right over my head ;) Keep in mind that I am just a meddler, does
this mean that I need to use this stuff ?
....

No, you do not need to use the varargs stuff. Unless the function being cast to
the omnifunc_type is varargs to begin with. As long as the correct argument
types and order are being used, the non-varargs function that's been cast to
omnifunc_type will be happy.

This would have done wonders for one open-source Prolog interpreter I considered
fixing a while back. But it had more severe design problems than eschewing this
function pointer cast.
.



Relevant Pages

  • Casting pointers to functions of different types
    ... It has to cast a function pointer to some ... Code which stored function pointer in array of unsigned ... typedef void; ... void marshal (AFunc func, int *args) ...
    (comp.lang.c)
  • Re: Function Pointers
    ... Just a heads-up - you don't need the cast. ... lossless conversion between void * and function pointers, ... I thought you couldn't have a generic function pointer like the 'void ... there is no generic function pointer type. ...
    (comp.lang.c)
  • Re: Plugins as game data
    ... Once you have the address of the function, cast it using a function ... // cast your void * address into the right function pointer ... somefunction(fmt, vp); ...
    (rec.games.roguelike.development)
  • Re: Plugins as game data
    ... Once you have the address of the function, cast it using a function ... // cast your void * address into the right function pointer ... Assuming that all data types involved in the function call are ...-friendly, ...
    (rec.games.roguelike.development)
  • Re: bug in visual studio .net 2003 - breakpoints and memcpy
    ... > from a function pointer to void*, ... > listed among the possible conversions. ... Otherwise the conversion is an error and the "double cast" doesn't ...
    (microsoft.public.win32.programmer.kernel)

Loading