summaryrefslogtreecommitdiff
path: root/commands.h
diff options
context:
space:
mode:
Diffstat (limited to 'commands.h')
-rw-r--r--commands.h73
1 files changed, 44 insertions, 29 deletions
diff --git a/commands.h b/commands.h
index 2e364ac..92801bd 100644
--- a/commands.h
+++ b/commands.h
@@ -8,20 +8,20 @@
#include <functional>
enum MoveDir
-{
- UP,
- RIGHT,
- DOWN,
- LEFT
-};
+ {
+ UP,
+ RIGHT,
+ DOWN,
+ LEFT
+ };
enum CommandArgType
-{
- STR,
- NUM,
- MOVDIR,
- STR_REST,
- NUM_ARR_REST
-};
+ {
+ STR,
+ NUM,
+ MOVDIR,
+ STR_REST,
+ NUM_ARR_REST
+ };
struct NumArr
{
@@ -40,27 +40,32 @@ struct Command
{
const std::string name;
const std::function<void(std::any&, const CommandArg* argv)> func;
+ const std::function<void(const CommandArg* argv)> staticFunc;
const int argc;
CommandArgType* argTypes;
std::any* module;
};
class CommandsModule
{
- private:
- std::vector<Command> commandList;
- std::vector<std::string> splitCommand(std::string command);
- CommandArg* getCommandArgs(std::vector<std::string>& args, const CommandArgType* argTypes, const int argc);
- const void printHello(const CommandArg* argv);
- const void echo(const CommandArg* argv);
- public:
- CommandsModule();
- ~CommandsModule();
- template <class T>
- void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module);
- void addCommand(Command c);
- Command* lookupCommand(std::string name);
- void runCommand(std::string command);
- Err checkCommand(std::string command);
+private:
+ std::vector<Command> commandList;
+ std::vector<std::string> splitCommand(std::string command);
+ CommandArg* getCommandArgs(std::vector<std::string>& args, const CommandArgType* argTypes, const int argc);
+ const void printHello(const CommandArg* argv);
+ const void echo(const CommandArg* argv);
+public:
+ CommandsModule();
+ ~CommandsModule();
+ template <class T>
+ void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module);
+ void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes);
+ template <class T>
+ void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector<CommandArgType> argTypes, T* module);
+ void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector<CommandArgType> argTypes);
+ void addCommand(Command c);
+ Command* lookupCommand(std::string name);
+ void runCommand(std::string command);
+ Err checkCommand(std::string command);
};
// YES I KNOW THIS IS BAD
@@ -68,6 +73,16 @@ class CommandsModule
template <class T>
void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module)
{
- Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, argc, argTypes, (std::any*)module};
+ Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module};
addCommand(c);
}
+template <class T>
+void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector<CommandArgType> argTypes, T* module)
+{
+ CommandArgType* argTypesArr = new CommandArgType[argc];
+ for(int i = 0; i < argc; i++)
+ {
+ argTypesArr[i] = argTypes[i];
+ }
+ addCommand(name, func, argc, argTypesArr, module);
+}