Re: Plugins as game data



On 2007-12-17 22:37:03, Kenneth 'Bessarion' Boyd <zaimoni@xxxxxxxxxxx> 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)(....)

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 ?

/* Begin the Varargs Stuff */
va_start(vp, fmt);

/* Format the args, save the length */
(void)somefunction( fmt, vp);

/* End the Varargs Stuff */
va_end(vp);

?

--
* Go to Hell (http://hellband.googlepages.com/index.html), now version 0.8.6! *
.



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: 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 ... you do not need to use the varargs stuff. ...
    (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)
  • function pointers with unspecified argument number
    ... to function pointer with unspecified number of arguments and then call ... void f2; ... fptr fp1 = f1; ... f2(const char *fmt, ...) ...
    (comp.lang.c)

Loading