databuffer.h

changeset 68
588cc27e84bb
parent 63
0557babc8675
child 69
29a3e669d648
--- a/databuffer.h	Wed Dec 19 04:20:02 2012 +0200
+++ b/databuffer.h	Wed Dec 19 13:44:18 2012 +0200
@@ -43,6 +43,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "common.h"
+#include "stringtable.h"
 
 #define MAX_MARKS 512
 
@@ -279,6 +280,22 @@
 			count += !!refs[u];
 		return count;
 	}
+	
+	// Write a float into the buffer
+	void WriteFloat (str floatstring) {
+		// TODO: Casting float to word causes the decimal to be lost.
+		// Find a way to store the number without such loss.
+		float val = atof (floatstring);
+		Write<word> (DH_PUSHNUMBER);
+		Write<word> (static_cast<word> ((val > 0) ? val : -val));
+		if (val < 0)
+			Write<word> (DH_UNARYMINUS);
+	}
+	
+	void WriteString (str string) {
+		Write<word> (DH_PUSHSTRINGINDEX);
+		Write<word> (PushToStringTable (string));
+	}
 };
 
 #endif // __DATABUFFER_H__
\ No newline at end of file

mercurial