Hi,
I'm creating a console for my game, I plan on having commands and I was wondering what's the best way to implement them? Such as, converting the text into functions, ie 'exit' quits, 'setres x y' sets the resolution.
I was thinking of having some sort of table like:
And then a function that parses the command and relates it to the table, otherwise command not found. Or is there a cleaner / better way? Also what's the best way to list the args the function will take (and call it accordingly).Code:struct consoleCommands_t {
char * cmd;
void * func;
/* should I have some sort of list of the arguments the fn takes? */
} commands[] = { {"setres", &consoleSetRes, /* list of args it takes (ie 2 ints) */}};
static void consoleSetRes(int x, int y)
{
/* changes the res */
return;
}
Thanks in advance :)