src/format.h

changeset 75
bf8c57437231
parent 73
1ee9b312dc18
child 79
2425fa6a4f21
--- a/src/format.h	Mon Jan 13 00:15:38 2014 +0200
+++ b/src/format.h	Mon Jan 13 23:44:15 2014 +0200
@@ -1,5 +1,5 @@
 /*
-	Copyright (c) 2013-2014, Santeri Piippo
+	Copyright (c) 2014, Santeri Piippo
 	All rights reserved.
 
 	Redistribution and use in source and binary forms, with or without
@@ -38,8 +38,9 @@
 {
 	public:
 		format_arg (const string& a) : m_string (a) {}
-		format_arg (int a) : m_string (a) {}
-		format_arg (long a) : m_string (a) {}
+		format_arg (char a) : m_string (a) {}
+		format_arg (int a) : m_string (string::from_number (a)) {}
+		format_arg (long a) : m_string (string::from_number (a)) {}
 		format_arg (const char* a) : m_string (a) {}
 
 		format_arg (void* a)
@@ -99,6 +100,20 @@
 	return custom_format (a, "%d");
 }
 
+class script_error : public std::exception
+{
+	public:
+		script_error (const string& msg) : m_msg (msg) {}
+
+		inline const char* what() const throw()
+		{
+			return m_msg.c_str();
+		}
+
+	private:
+		string m_msg;
+};
+
 string format_args (const list<format_arg>& args);
 void print_args (FILE* fp, const list<format_arg>& args);
 void do_fatal (const list<format_arg>& args);
@@ -107,10 +122,12 @@
 # define format(...) format_args({ __VA_ARGS__ })
 # define fprint(A, ...) print_args( A, { __VA_ARGS__ })
 # define print(...) print_args( stdout, { __VA_ARGS__ })
+# define error(...) throw script_error (format (__VA_ARGS__))
 #else
 string format (void, ...);
 void fprint (FILE* fp, ...);
 void print (void, ...);
+void error (void, ...);
 #endif
 
 #ifndef IN_IDE_PARSER

mercurial