Codechange: use std::string_view for console commands

This commit is contained in:
Rubidium
2025-04-20 14:10:36 +02:00
committed by rubidium42
parent f04cf54939
commit 365eed533d
4 changed files with 257 additions and 257 deletions

View File

@@ -29,8 +29,8 @@ enum ConsoleHookResult : uint8_t {
* If you want to handle multiple words as one, enclose them in double-quotes
* eg. 'say "hello everybody"'
*/
typedef bool IConsoleCmdProc(uint8_t argc, char *argv[]);
typedef ConsoleHookResult IConsoleHook(bool echo);
using IConsoleCmdProc = bool(std::span<std::string_view>);
using IConsoleHook = ConsoleHookResult(bool);
struct IConsoleCmd {
IConsoleCmd(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook) : name(name), proc(proc), hook(hook) {}
@@ -52,7 +52,7 @@ struct IConsoleCmd {
* - ";" allows for combining commands (see example 'ng')
*/
struct IConsoleAlias {
IConsoleAlias(const std::string &name, const std::string &cmdline) : name(name), cmdline(cmdline) {}
IConsoleAlias(const std::string &name, std::string_view cmdline) : name(name), cmdline(cmdline) {}
std::string name; ///< name of the alias
std::string cmdline; ///< command(s) that is/are being aliased
@@ -70,7 +70,7 @@ struct IConsole
/* Commands */
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr);
static IConsoleCmd *CmdGet(const std::string &name);
static void AliasRegister(const std::string &name, const std::string &cmd);
static void AliasRegister(const std::string &name, std::string_view cmd);
static IConsoleAlias *AliasGet(const std::string &name);
};