From 6b3dff404248bcf03e0bf0463a8c53d8918f7eec Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 31 May 2023 20:55:49 +1200 Subject: Added support for commands without a module Also made it easier to add commands by making the ~addCommand~ function accept a vector for ~argTypes~ and then convert it. --- commands.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'commands.cpp') diff --git a/commands.cpp b/commands.cpp index 322d160..549775e 100644 --- a/commands.cpp +++ b/commands.cpp @@ -47,6 +47,20 @@ void CommandsModule::addCommand(Command c) } commandList.push_back(c); } +void CommandsModule::addCommand(std::string name, const void (*func)(const CommandArg *), const int argc, CommandArgType *argTypes) +{ + Command c = {name, nullptr, func, argc, argTypes, nullptr}; + addCommand(c); +} +void CommandsModule::addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes) +{ + CommandArgType* argTypesArr = new CommandArgType[argc]; + for(int i = 0; i < argc; i++) + { + argTypesArr[i] = argTypes[i]; + } + addCommand(name, func, argc, argTypesArr); +} struct NameMatches { @@ -145,7 +159,10 @@ void CommandsModule::runCommand(string command) CommandArg* args = getCommandArgs(split, cmd->argTypes, cmd->argc); try { - cmd->func(*cmd->module, args); + if(cmd->module == nullptr) + cmd->staticFunc(args); + else + cmd->func(*cmd->module, args); } catch (Err e) { -- cgit v1.2.3