36 |
36 |
37 static List<CommandInfo*> gCommands; |
37 static List<CommandInfo*> gCommands; |
38 |
38 |
39 // ============================================================================ |
39 // ============================================================================ |
40 // |
40 // |
41 void AddCommandDefinition (CommandInfo* comm) |
41 void addCommandDefinition (CommandInfo* comm) |
42 { |
42 { |
43 // Ensure that there is no conflicts |
43 // Ensure that there is no conflicts |
44 for (CommandInfo* it : gCommands) |
44 for (CommandInfo* it : gCommands) |
45 if (it->number == comm->number) |
45 if (it->number == comm->number) |
46 Error ("Attempted to redefine command #%1 (%2) as %3", |
46 error ("Attempted to redefine command #%1 (%2) as %3", |
47 gCommands[comm->number]->name, comm->name); |
47 gCommands[comm->number]->name, comm->name); |
48 |
48 |
49 gCommands << comm; |
49 gCommands << comm; |
50 } |
50 } |
51 |
51 |
52 // ============================================================================ |
52 // ============================================================================ |
53 // Finds a command by name |
53 // Finds a command by name |
54 CommandInfo* FindCommandByName (String fname) |
54 CommandInfo* findCommandByName (String fname) |
55 { |
55 { |
56 for (CommandInfo* comm : gCommands) |
56 for (CommandInfo* comm : gCommands) |
57 { |
57 { |
58 if (fname.ToUppercase() == comm->name.ToUppercase()) |
58 if (fname.toUppercase() == comm->name.toUppercase()) |
59 return comm; |
59 return comm; |
60 } |
60 } |
61 |
61 |
62 return null; |
62 return null; |
63 } |
63 } |
64 |
64 |
65 // ============================================================================ |
65 // ============================================================================ |
66 // |
66 // |
67 // Returns the prototype of the command |
67 // Returns the prototype of the command |
68 // |
68 // |
69 String CommandInfo::GetSignature() |
69 String CommandInfo::signature() |
70 { |
70 { |
71 String text; |
71 String text; |
72 text += DataTypeName (returnvalue); |
72 text += dataTypeName (returnvalue); |
73 text += ' '; |
73 text += ' '; |
74 text += name; |
74 text += name; |
75 |
75 |
76 if (args.IsEmpty() == false) |
76 if (args.isEmpty() == false) |
77 text += ' '; |
77 text += ' '; |
78 |
78 |
79 text += '('; |
79 text += '('; |
80 |
80 |
81 bool hasoptionals = false; |
81 bool hasoptionals = false; |
82 |
82 |
83 for (int i = 0; i < args.Size(); i++) |
83 for (int i = 0; i < args.size(); i++) |
84 { |
84 { |
85 if (i == minargs) |
85 if (i == minargs) |
86 { |
86 { |
87 hasoptionals = true; |
87 hasoptionals = true; |
88 text += '['; |
88 text += '['; |
89 } |
89 } |
90 |
90 |
91 if (i) |
91 if (i) |
92 text += ", "; |
92 text += ", "; |
93 |
93 |
94 text += DataTypeName (args[i].type); |
94 text += dataTypeName (args[i].type); |
95 text += ' '; |
95 text += ' '; |
96 text += args[i].name; |
96 text += args[i].name; |
97 |
97 |
98 if (i >= minargs) |
98 if (i >= minargs) |
99 { |
99 { |
|
100 bool isString = args[i].type == TYPE_String; |
100 text += " = "; |
101 text += " = "; |
101 |
102 |
102 bool is_string = args[i].type == TYPE_String; |
103 if (isString) |
103 |
|
104 if (is_string) |
|
105 text += '"'; |
104 text += '"'; |
106 |
105 |
107 text += String::FromNumber (args[i].defvalue); |
106 text += String::fromNumber (args[i].defvalue); |
108 |
107 |
109 if (is_string) |
108 if (isString) |
110 text += '"'; |
109 text += '"'; |
111 } |
110 } |
112 } |
111 } |
113 |
112 |
114 if (hasoptionals) |
113 if (hasoptionals) |