|
5 | 5 |
|
6 | 6 | struct LacoState; |
7 | 7 |
|
| 8 | +/** |
| 9 | + * Generalized function pointer for handling commands from from either a |
| 10 | + * command line flag or a command inside of laco itself. |
| 11 | + */ |
| 12 | +typedef void (*LacoHandler)(struct LacoState* laco, const char** arguments); |
| 13 | + |
| 14 | +/** |
| 15 | + * A representation of each command with a list of string matches and a |
| 16 | + * function pointer to the behavior of said command. When there is a match |
| 17 | + * to one of the string, this function will be called and passed in the |
| 18 | + * appropriate arguments. |
| 19 | + */ |
| 20 | +struct LacoCommand { |
| 21 | + const char** matches; |
| 22 | + LacoHandler handler; |
| 23 | +}; |
| 24 | + |
8 | 25 | /** |
9 | 26 | * Load a line into the lua stack to evaluated later. This function will |
10 | 27 | * return false if there is no line input to load. |
@@ -51,4 +68,15 @@ char** laco_split_by(const char split_with, char* string, |
51 | 68 | #define laco_line_to_words(line) \ |
52 | 69 | laco_split_by(' ', line, 1) |
53 | 70 |
|
| 71 | +/** |
| 72 | + * Goes through each instance from the list of commands and see if there is |
| 73 | + * a match with for command_keyword. When there is a match, the defined |
| 74 | + * handler inside the LacoCommand gets called -- passing in LacoState and |
| 75 | + * the arguments. The list of commands expects the last entry of the array |
| 76 | + * to be `{ NULL, NULL }` for ease of iteration. |
| 77 | + */ |
| 78 | +void laco_dispatch(const struct LacoCommand* commands, |
| 79 | + struct LacoState* laco, const char* command_keyword, |
| 80 | + const char** arguments); |
| 81 | + |
54 | 82 | #endif /* LACO_UTIL_H */ |
0 commit comments