Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 3 and Version 4 of code/doc/CommandExecutor


Ignore:
Timestamp:
Oct 7, 2008, 6:22:07 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/CommandExecutor

    v3 v4  
    1414== Usage ==
    1515=== execute() ===
     16'''execute('''''string''''')''' parses the string and searches a [wiki:ConsoleCommand] with the given name. Given arguments (separated by spaces) are used to execute the !ConsoleCommand.
     17
     18''string'' has to be a complete !ConsoleCommand (complete in the sense that the command exists and all needed arguments are given), otherwise the !CommandExecutor returns false and sends an [wiki:Debug error message] to the output.
     19
     20 * Example 1:
     21{{{
     22CommandExecutor::execute("myfunction 10");
     23}}}
     24    This is equal to ''myfunction(10)'' provided that "myfunction" was declared as a !ConsoleCommand.
     25
     26 * Example 2:
     27{{{
     28CommandExecutor::execute("MyClass myfunction 0.1 0.2 0.3");
     29}}}
     30    This is equal to ''MyClass::myfunction(0.1, 0.2, 0.3)'' provided that the function "myfunction" of the class "MyClass" was declared as a !ConsoleCommand.
     31
     32
    1633=== hint() ===
     34'''hint('''''string''''')''' returns a help message providing some information about an incomplete command (incomplete in the sense that not all possible arguments are yet given). This includes a list of the requested arguments and default-values (if any). If there's a description of the command, it is displayed too.
     35
     36If ''string'' doesn't describe a unique !ConsoleCommand, hint returns a list of possible commands matching the already given fragment. It also returns a list of possible arguments if there's an [wiki:ArgumentCompleter] declared for the current argument.
     37
     38 * Example 1 (function description, argument list, default values):
     39{{{
     40class MyClass
     41{
     42    static void myfunction(int value, bool condition, const std::string& name);
     43};
     44
     45SetConsoleCommand(MyClass, myfunction, true)
     46    .defaultValue(1, false)     // 1 refers to the second argument (condition)
     47    .defaultValue(2, "Default") // 2 refers to the third argument (name)
     48    .description("This is a useless testfunction!");
     49
     50// Get the hint:
     51CommandExecutor::hint("MyClass myfunction");
     52
     53// Output:
     54 > This is a useless testfunction!
     55 > myfunction: {int} [bool=false] [string=Default]
     56}}}
     57
     58 * Example 2 (possible classes and functions, possible arguments):
     59{{{
     60class MyClass
     61{
     62    static void myfunction(int value, bool condition, const std::string& name);
     63};
     64
     65SetConsoleCommand(MyClass, myfunction, true)
     66    .defaultValue(1, false)     // 1 refers to the second argument (condition)
     67    .defaultValue(2, "Default") // 2 refers to the third argument (name)
     68    .description("This is a useless testfunction!")
     69    .argumentCompleter(2, autocompletion::mynames()); // argument completion for the name
     70
     71// First try an empty string: We get a list of all possible classes and functions
     72CommandExecutor::hint("");
     73 > myfunction
     74 > MyClass
     75
     76// Now start typing the classname: We get a list of all possible
     77// classnames (only MyClass in our example)
     78CommandExecutor::hint("mycl");
     79 > MyClasses
     80
     81// We've finished the classname, now we get a list of all functions
     82// of this class (only myfunction in our example)
     83CommandExecutor::hint("MyClass ");
     84 > myfunction
     85
     86// There's still only one possible function:
     87CommandExecutor::hint("MyClass myfunc");
     88 > myfunction
     89
     90// Now we get the hint from example 1
     91CommandExecutor::hint("MyClass myfunction ");
     92 > This is a useless testfunction!
     93 > myfunction: {int} [bool=false] [string=Default]
     94
     95// As soon as we start typing the third argument (notice the space after the
     96// second argument) we get a list of all possible arguments for "name" because
     97// we've added an ArgumentCompletor:
     98CommandExecutor::hint("MyClass myfunction 10 true ");
     99 > Adam Bernd Claude Default Eric Elton Fred Hank
     100
     101// We start typing the third argument, the list of possible arguments reduces
     102// to arguments starting with the given letter:
     103CommandExecutor::hint("MyClass myfunction 10 true e");
     104 > Eric Elton
     105
     106// We type another letter and the list reduces even more:
     107CommandExecutor::hint("MyClass myfunction 10 true er");
     108 > Eric
     109}}}
     110
    17111=== complete() ===
     112'''complete('''''string''''')'''
     113
    18114=== evaluate() ===
    19115