Advertisement

Function call with arguements

Started by January 04, 2009 11:43 PM
0 comments, last by SiCrane 15 years, 10 months ago
Currently, when you want to call a function with arguments, you need to do following steps ( if its not correct, can you point me out): * get ID of the method or function * push all its arguements one by one by set SetObject or similar methods. * call execute functions * get the return value. GetReturnByte or similar methods to return the result. can we use ... inside of stdarg.h, to write a function, inside of script, it will get the function declearation and push them on the stack, or do watever script needs to do. My example: define an interface int callFunction(char* functionName ...); The rest of the function should contains: the return Value, and arguments. when we call function bool printf(const string ∈); we can do this: engine->callFunction("printf", returnValue, string("how are you")); Is there any technical concern to do this way? Cheers
Basically, this can't be done with variadic functions. At least not the way you seem to want to use it. As soon as you try passing a class object to a variadic function, all hell breaks loose. Best case scenario generally involves memory leaks. I've had some success with using boost preprocessor and creating template functions to do this, and C++0x vararg templates can probably handle it more elegantly when the compiler support for it finally becomes widespread.

This topic is closed to new replies.

Advertisement