| 29 #ifndef BOTC_TYPES_H |
29 #ifndef BOTC_TYPES_H |
| 30 #define BOTC_TYPES_H |
30 #define BOTC_TYPES_H |
| 31 |
31 |
| 32 #include <cstdlib> |
32 #include <cstdlib> |
| 33 #include <stdexcept> |
33 #include <stdexcept> |
| |
34 #include "str.h" |
| 34 |
35 |
| 35 static const std::nullptr_t null = nullptr; |
36 static const std::nullptr_t null = nullptr; |
| |
37 |
| |
38 // Byte datatype |
| |
39 typedef int32_t word; |
| |
40 typedef unsigned char byte; |
| |
41 |
| |
42 // Parser mode: where is the parser at? |
| |
43 enum parsermode_e |
| |
44 { |
| |
45 MODE_TOPLEVEL, // at top level |
| |
46 MODE_EVENT, // inside event definition |
| |
47 MODE_MAINLOOP, // inside mainloop |
| |
48 MODE_ONENTER, // inside onenter |
| |
49 MODE_ONEXIT, // inside onexit |
| |
50 }; |
| |
51 |
| |
52 enum type_e |
| |
53 { |
| |
54 TYPE_UNKNOWN = 0, |
| |
55 TYPE_VOID, |
| |
56 TYPE_INT, |
| |
57 TYPE_STRING, |
| |
58 TYPE_BOOL, |
| |
59 }; |
| |
60 |
| |
61 // Script mark and reference |
| |
62 struct byte_mark |
| |
63 { |
| |
64 string name; |
| |
65 int pos; |
| |
66 }; |
| |
67 |
| |
68 struct mark_reference |
| |
69 { |
| |
70 byte_mark* target; |
| |
71 int pos; |
| |
72 }; |
| |
73 |
| |
74 class script_error : public std::exception |
| |
75 { |
| |
76 public: |
| |
77 script_error (const string& msg) : m_msg (msg) {} |
| |
78 |
| |
79 inline const char* what() const throw() |
| |
80 { |
| |
81 return m_msg.c_str(); |
| |
82 } |
| |
83 |
| |
84 private: |
| |
85 string m_msg; |
| |
86 }; |
| |
87 |
| |
88 // ==================================================================== |
| |
89 // Generic union |
| |
90 template <class T> union generic_union |
| |
91 { |
| |
92 T as_t; |
| |
93 byte as_bytes[sizeof (T)]; |
| |
94 char as_chars[sizeof (T)]; |
| |
95 double as_double; |
| |
96 float as_float; |
| |
97 int as_int; |
| |
98 word as_word; |
| |
99 }; |
| 36 |
100 |
| 37 template<class T> inline T abs (T a) |
101 template<class T> inline T abs (T a) |
| 38 { |
102 { |
| 39 return (a >= 0) ? a : -a; |
103 return (a >= 0) ? a : -a; |
| 40 } |
104 } |