/** Adds a console command for Lua. * No I_Errors allowed; return a negative code instead. * * \param name Name of the command. */ int COM_AddLuaCommand(const char *name) { xcommand_t *cmd; // fail if the command is a variable name if (CV_StringValue(name)[0] != '\0') return -1; // command already exists for (cmd = com_commands; cmd; cmd = cmd->next) { if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! { // replace the built in command. cmd->function = COM_Lua_f; return 1; } } // Add a new command. cmd = ZZ_Alloc(sizeof *cmd); cmd->name = name; cmd->function = COM_Lua_f; cmd->next = com_commands; com_commands = cmd; return 0; }
/** Adds a console command. * * \param name Name of the command. * \param func Function called when the command is run. */ void COM_AddCommand(const char *name, com_func_t func) { xcommand_t *cmd; // fail if the command is a variable name if (CV_StringValue(name)[0] != '\0') { I_Error("%s is a variable name\n", name); return; } // fail if the command already exists for (cmd = com_commands; cmd; cmd = cmd->next) { if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! { I_Error("Command %s already exists\n", name); return; } } cmd = ZZ_Alloc(sizeof *cmd); cmd->name = name; cmd->function = func; cmd->next = com_commands; com_commands = cmd; }
/** Adds a console command. * * \param name Name of the command. * \param func Function called when the command is run. */ void COM_AddCommand(const char *name, com_func_t func) { xcommand_t *cmd; // fail if the command is a variable name if (CV_StringValue(name)[0] != '\0') { I_Error("%s is a variable name\n", name); return; } // fail if the command already exists for (cmd = com_commands; cmd; cmd = cmd->next) { if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! { // don't I_Error for Lua commands // Lua commands can replace game commands, and they have priority. // BUT, if for some reason we screwed up and made two console commands with the same name, // it's good to have this here so we find out. if (cmd->function != COM_Lua_f) I_Error("Command %s already exists\n", name); return; } } cmd = ZZ_Alloc(sizeof *cmd); cmd->name = name; cmd->function = func; cmd->next = com_commands; com_commands = cmd; }