Re: Plugins as game data



On 2007-12-17 22:02:54, konijn_ <konijn@xxxxxxxxx> 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.
.



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 ... somefunction(fmt, vp); ...
    (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)
  • Re: User defined stack for threads in Linux 2.6.11 + glibc 2.3.5
    ... printf, sleep(), and pthread_exitaren't async-cancel-safe, so the ... behavior is undefined if the thread running that code is actually ... The casting of 'fn' to void* is actually a constraint violation. ... structure that holds the function pointer and the value to pass as its ...
    (comp.programming.threads)

Loading