| 166 |
166 |
| 167 // stateSpawn must be defined! |
167 // stateSpawn must be defined! |
| 168 if (!g_stateSpawnDefined) |
168 if (!g_stateSpawnDefined) |
| 169 ParserError ("script must have a state named `stateSpawn`!"); |
169 ParserError ("script must have a state named `stateSpawn`!"); |
| 170 |
170 |
| |
171 // If the last state did not have a main loop, define a dummy one now. |
| |
172 if (!gotMainLoop) { |
| |
173 w->Write (DH_MAINLOOP); |
| |
174 w->Write (DH_ENDMAINLOOP); |
| |
175 } |
| |
176 |
| 171 /* |
177 /* |
| 172 // State |
178 // State |
| 173 w->WriteState ("stateSpawn"); |
179 w->WriteState ("stateSpawn"); |
| 174 |
180 |
| 175 w->Write (DH_ONENTER); |
181 w->Write (DH_ONENTER); |
| 190 void ScriptReader::ParseCommand (CommandDef* comm, ObjWriter* w) { |
196 void ScriptReader::ParseCommand (CommandDef* comm, ObjWriter* w) { |
| 191 // If this was defined at top-level, we stop right at square one! |
197 // If this was defined at top-level, we stop right at square one! |
| 192 if (g_CurMode == MODE_TOPLEVEL) |
198 if (g_CurMode == MODE_TOPLEVEL) |
| 193 ParserError ("no commands allowed at top level!"); |
199 ParserError ("no commands allowed at top level!"); |
| 194 |
200 |
| 195 w->Write<long> (DH_COMMAND); |
|
| 196 w->Write<long> (comm->number); |
|
| 197 w->Write<long> (comm->maxargs); |
|
| 198 MustNext ("("); |
201 MustNext ("("); |
| 199 int curarg = 0; |
202 int curarg = 0; |
| 200 while (1) { |
203 while (1) { |
| 201 if (curarg >= comm->maxargs) { |
204 if (curarg >= comm->maxargs) { |
| 202 if (!PeekNext().compare (",")) |
205 if (!PeekNext().compare (",")) |
| 218 // Needs to cater for string arguments too... |
221 // Needs to cater for string arguments too... |
| 219 if (!token.isnumber()) |
222 if (!token.isnumber()) |
| 220 ParserError ("argument %d (`%s`) is not a number", curarg, token.chars()); |
223 ParserError ("argument %d (`%s`) is not a number", curarg, token.chars()); |
| 221 |
224 |
| 222 int i = atoi (token.chars ()); |
225 int i = atoi (token.chars ()); |
| |
226 w->Write<long> (DH_PUSHNUMBER); |
| 223 w->Write<long> (i); |
227 w->Write<long> (i); |
| 224 |
228 |
| 225 if (curarg < comm->numargs - 1) { |
229 if (curarg < comm->numargs - 1) { |
| 226 MustNext (","); |
230 MustNext (","); |
| 227 } else if (curarg < comm->maxargs - 1) { |
231 } else if (curarg < comm->maxargs - 1) { |
| 238 } |
242 } |
| 239 MustNext (";"); |
243 MustNext (";"); |
| 240 |
244 |
| 241 // If the script skipped any optional arguments, fill in defaults. |
245 // If the script skipped any optional arguments, fill in defaults. |
| 242 while (curarg < comm->maxargs) { |
246 while (curarg < comm->maxargs) { |
| |
247 w->Write<long> (DH_PUSHNUMBER); |
| 243 w->Write<long> (comm->defvals[curarg]); |
248 w->Write<long> (comm->defvals[curarg]); |
| 244 curarg++; |
249 curarg++; |
| 245 } |
250 } |
| |
251 |
| |
252 w->Write<long> (DH_COMMAND); |
| |
253 w->Write<long> (comm->number); |
| |
254 w->Write<long> (comm->maxargs); |
| 246 } |
255 } |