Commands w/ arguments are now written correctly.

Sat, 14 Jul 2012 18:03:37 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 14 Jul 2012 18:03:37 +0300
changeset 19
66993500719f
parent 18
dbcc3b784234
child 20
d7b13805d1e0

Commands w/ arguments are now written correctly.

commands.cxx file | annotate | diff | comparison | revisions
parser.cxx file | annotate | diff | comparison | revisions
scriptreader.cxx file | annotate | diff | comparison | revisions
--- a/commands.cxx	Sat Jul 14 17:39:43 2012 +0300
+++ b/commands.cxx	Sat Jul 14 18:03:37 2012 +0300
@@ -55,7 +55,7 @@
 	CommandDef* curdef = g_CommDef;
 	unsigned int numCommDefs = 0; 
 	
-	while (r->PeekNext().compare ("") != 0) {
+	while (r->PeekNext().len()) {
 		CommandDef* comm = new CommandDef;
 		comm->next = NULL;
 		
--- a/parser.cxx	Sat Jul 14 17:39:43 2012 +0300
+++ b/parser.cxx	Sat Jul 14 18:03:37 2012 +0300
@@ -168,6 +168,12 @@
 	if (!g_stateSpawnDefined)
 		ParserError ("script must have a state named `stateSpawn`!");
 	
+	// If the last state did not have a main loop, define a dummy one now.
+	if (!gotMainLoop) {
+		w->Write (DH_MAINLOOP);
+		w->Write (DH_ENDMAINLOOP);
+	}
+	
 	/*
 	// State
 	w->WriteState ("stateSpawn");
@@ -192,9 +198,6 @@
 	if (g_CurMode == MODE_TOPLEVEL)
 		ParserError ("no commands allowed at top level!");
 	
-	w->Write<long> (DH_COMMAND);
-	w->Write<long> (comm->number);
-	w->Write<long> (comm->maxargs);
 	MustNext ("(");
 	int curarg = 0;
 	while (1) {
@@ -220,6 +223,7 @@
 			ParserError ("argument %d (`%s`) is not a number", curarg, token.chars());
 		
 		int i = atoi (token.chars ());
+		w->Write<long> (DH_PUSHNUMBER);
 		w->Write<long> (i);
 		
 		if (curarg < comm->numargs - 1) {
@@ -240,7 +244,12 @@
 	
 	// If the script skipped any optional arguments, fill in defaults.
 	while (curarg < comm->maxargs) {
+		w->Write<long> (DH_PUSHNUMBER);
 		w->Write<long> (comm->defvals[curarg]);
 		curarg++;
 	}
+	
+	w->Write<long> (DH_COMMAND);
+	w->Write<long> (comm->number);
+	w->Write<long> (comm->maxargs);
 }
\ No newline at end of file
--- a/scriptreader.cxx	Sat Jul 14 17:39:43 2012 +0300
+++ b/scriptreader.cxx	Sat Jul 14 18:03:37 2012 +0300
@@ -45,7 +45,7 @@
 #include "common.h"
 #include "scriptreader.h"
 
-bool IsDelimeter (char c) {
+static bool IsWhitespace (char c) {
 	// These characters are invisible, thus considered whitespace
 	if (c <= 32 || c == 127 || c == 255)
 		return true;
@@ -111,7 +111,7 @@
 			break;
 		}
 		
-		if (IsDelimeter (c)) {
+		if (IsWhitespace (c)) {
 			// Don't break if we haven't gathered anything yet.
 			if (tmp.len())
 				break;
@@ -120,7 +120,8 @@
 		}
 	}
 	
-	// If we got nothing here, read failed.
+	// If we got nothing here, read failed. This should
+	// only hapen in the case of EOF.
 	if (!tmp.len()) {
 		token = "";
 		return false;

mercurial