Game Development Community

Dynamic argument list in a DefineEngineMethod ?

by Steven Saric · in Torque 3D Professional · 06/21/2012 (5:16 am) · 4 replies

The title basically says it all. But is it possible to have a dynamic argument list when declaring a DefineEngineMethod?

This is relatively easy using a ConsoleMethod eg:

ConsoleMethod( SimComponent, addComponents, bool, 3, 64, "%obj.addComponents( %compObjName, %compObjName2, ... );\n"





For a normal function you would do something like this:

#include <stdarg.h>
#include <stdio.h> 

void print(char *one, ...) 
{ 
    va_list va; 
    char *p; 
    
    for(p = one; p; p = va_arg(va, char *)) 
    {
        puts(p); 
    }
    
    va_end(va); 
    
    return; 
}



------------------------

Does something similar work for the user-defined args in a DefineEngineMethod?



Eg. Converting the above console method, could I go and do something like this:
(or is there an actual way to do it with a DefineEngineMethod, it doesnt like the ... )

DefineEngineMethod( SimComponent, addComponents, bool, ( const char* one, ... ),,

About the author

Programmer --------- http://steven.es/

Recent Threads

  • Master Server query list?

  • #1
    06/21/2012 (8:58 pm)
    I don't believe DefineEngineMethod supports varArgs. You might look into the ConsoleMethod macro instead. It's not preferred - If I recall, the intent at one time was to deprecate the ConsoleFunction and ConsoleMethod macros....

    I could be mistaken - anyone else care to chime in on this one?
    #2
    06/21/2012 (10:24 pm)
    I was planning on removing ConsoleMethod/ConsoleFunction entirely. So sadly, it's not much help :(

    So, it looks like I might have some fun over the weekend trying to convert DefineEngineMethod into a variadic macro
    #3
    06/23/2012 (11:04 am)
    Maybe a template version of that would work - though my template programming skills aren't up to that task it seems like it should be possible.
    #4
    06/26/2012 (4:16 am)
    I'm not aware of a way to do this unless you were to change the trampoline and template code. I would be very interested to see it done though.