Torque Engine Source Code - Console.h
by Yujiao Guo · in Torque Game Engine · 11/22/2007 (8:22 pm) · 3 replies
# define ConsoleFunction(name,returnType,minArgs,maxArgs,usage1) \
static returnType c##name(SimObject *, S32, const char **argv); \
static ConsoleConstructor g##name##obj(NULL,#name,c##name,usage1,minArgs,maxArgs); \
static returnType c##name(SimObject *, S32 argc, const char **argv)
Where does const char **argv comes from and what does it mean?
Thanks!!!
updated:
1.
how comes you can use one define to define 3 versions of fuctions. How does the compiler determine which definition to use. For example: when will "static ConsoleConstructor g##name##obj(NULL,#name,c##name,usage1,minArgs,maxArgs);" be used?
hum...actually I think one #define defines 3 versions of functions all the time. Am I right?
2.
when you define foo as:
ConsoleFunction( foo, void, 2, 2, "foo - takes a number and prints the number + 1 to the console" )
How would it be defined?
Is it like this? static void cfoo(SimObject *, S32, const char **argv);
But then you are not passing in parameter values like SimObject *, S32.
Thanks!!!
I am trying to learn every bits of the engine. :}
static returnType c##name(SimObject *, S32, const char **argv); \
static ConsoleConstructor g##name##obj(NULL,#name,c##name,usage1,minArgs,maxArgs); \
static returnType c##name(SimObject *, S32 argc, const char **argv)
Where does const char **argv comes from and what does it mean?
Thanks!!!
updated:
1.
how comes you can use one define to define 3 versions of fuctions. How does the compiler determine which definition to use. For example: when will "static ConsoleConstructor g##name##obj(NULL,#name,c##name,usage1,minArgs,maxArgs);" be used?
hum...actually I think one #define defines 3 versions of functions all the time. Am I right?
2.
when you define foo as:
ConsoleFunction( foo, void, 2, 2, "foo - takes a number and prints the number + 1 to the console" )
How would it be defined?
Is it like this? static void cfoo(SimObject *, S32, const char **argv);
But then you are not passing in parameter values like SimObject *, S32.
Thanks!!!
I am trying to learn every bits of the engine. :}
#2
11/24/2007 (6:50 am)
Thank you. That is very helpful!
#3
I figured out if you do:
project > properties
+ configuration
+C/C++
+Command Line
type /EP under Addition options
Now when you compile or build it will spew all precompiler output into the output window.
But its impossible to find anything unless you create a new small .cpp file for testing exactly what you want ( as you reccomended ). I created the file Sourc1.cpp that looks like:
But this file will not compile... I mean its not even giving me the option to compile it. Any ideas whats going on, or an easier way to do this in general?
11/29/2007 (12:45 pm)
This would be a nice trick to know in general, for checking what all those nested defines precompile into. But any idea how I can do this in Visual Studio 2005?I figured out if you do:
project > properties
+ configuration
+C/C++
+Command Line
type /EP under Addition options
Now when you compile or build it will spew all precompiler output into the output window.
But its impossible to find anything unless you create a new small .cpp file for testing exactly what you want ( as you reccomended ). I created the file Sourc1.cpp that looks like:
#include <winnt.h> DECLARE_HANDLE(test);
But this file will not compile... I mean its not even giving me the option to compile it. Any ideas whats going on, or an easier way to do this in general?
Torque Owner Michael Bacon
Default Studio Name
If you create a simple test file (test.cc) and include Console.h at the top and create a ConsoleFunction. Then run your preprocessor (or tell your compiler to save the preprocessed output. You can see what the defines expand to.
1. All three functions are always defined.
2. Given your examples the above ConsoleFunction macro expands as follows. Your arguments are in bold.
I guess I could explain these three lines...
The first is a forward declaration of a function.
The second creates a static object of type "ConsoleConstructor" that registers the class, the usage, number of args, and the function we just declared.
Finally we have the function header itself, which leaves itself open for your brackets and code.