/// <summary> /// Initializes a new instance of thsi class. /// </summary> /// <param name="symbol">Function symbol describing the function to call.</param> /// <param name="thread">Script thread that function is embedded in.</param> public ScriptConsoleCommand(FunctionSymbol symbol, ScriptThread thread) { _thread = thread; _functionSymbol = symbol; ConsoleValueType[] parameters = new ConsoleValueType[symbol.ParameterCount]; for (int i = 0; i < parameters.Length; i++) { switch (((VariableSymbol)symbol.Symbols[i]).DataType.DataType) { case DataType.Bool: parameters[i] = ConsoleValueType.Bool; break; case DataType.Float: parameters[i] = ConsoleValueType.Float; break; case DataType.Int: parameters[i] = ConsoleValueType.Int; break; case DataType.String: parameters[i] = ConsoleValueType.String; break; } } _command = new ConsoleCommand(symbol.Identifier, new CommandDelegate(InvokeCommand), parameters); Console.Console.RegisterCommand(_command); }
/// <summary> /// Invokes the command. /// </summary> /// <param name="args">Arguments used to call the command.</param> private void InvokeCommand(object[] args) { ConsoleValueType[] parameters = new ConsoleValueType[_functionSymbol.ParameterCount]; for (int i = 0; i < parameters.Length; i++) { switch (((VariableSymbol)_functionSymbol.Symbols[i]).DataType.DataType) { case DataType.Bool: _thread.PassParameter((bool)args[i]); break; case DataType.Float: _thread.PassParameter((float)args[i]); break; case DataType.Int: _thread.PassParameter((int)args[i]); break; case DataType.String: _thread.PassParameter((string)args[i]); break; } } _thread.InvokeFunction(_functionSymbol); }
/// <summary> /// Initializes a new instance of this class with the /// given identifier and delegate. /// </summary> /// <param name="identifier">String to identify this console command.</param> /// <param name="del">Delegate to method to invoke when this command is called.</param> /// <param name="parameters">Array of parameter types describing this commands parameters.</param> public ConsoleCommand(string identifier, CommandDelegate del, ConsoleValueType[] parameters) { _identifier = identifier; _delegate = del; _parameters = parameters; }