VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
static void AVR.Core.AVR_DevConsole.command ( string  s,
bool  addToHistory = true 
)
inlinestatic

Execute a given console command.

Definition at line 211 of file AVR_DevConsole.cs.

211  {
212  if(addToHistory) {
213  command_history.Insert(0, s);
214  while(command_history.Count>command_history_limit) command_history.RemoveAt(0);
215  echo_command(s);
216  }
217 
218  s = s.Trim();
219 
220  string[] c = s.Split(' ');
221 
222  // Find the "best fit" - meaning the command whose min_args best fit the amount of given args
223  List<AVR_ConsoleCommand> cmds = commands.Where((cmd) => cmd.name == c[0]).ToList();
224  AVR_ConsoleCommand cmd = cmds.Where((cmd) => cmd.min_args <= c.Length - 1).OrderBy((cmd) => -cmd.min_args).FirstOrDefault();
225 
226  if(cmd != null && c.Length > cmd.min_args) {
227  cmd.func(c.Skip(1).ToArray());
228  }
229  else if(cmd == null && cmds.Count > 0) {
230  error("Command "+c[0]+" requires more arguments.");
231  }
232  else
233  {
234  error("Could not recognize command \"" + c[0] + "\"");
235  }
236 
237  OnCommand.Invoke(s);
238  }
static void error(string s)
Print a given error string on the console.
static void echo_command(string s)
static int command_history_limit
static List< string > command_history