GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
chaiscript_defines.hpp
Go to the documentation of this file.
1// This file is distributed under the BSD License.
2// See "license.txt" for details.
3// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4// Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5// http://www.chaiscript.com
6
7#ifndef CHAISCRIPT_DEFINES_HPP_
8#define CHAISCRIPT_DEFINES_HPP_
9
10#ifdef _MSC_VER
11#define CHAISCRIPT_STRINGIZE(x) "" #x
12#define CHAISCRIPT_STRINGIZE_EXPANDED(x) CHAISCRIPT_STRINGIZE(x)
13#define CHAISCRIPT_COMPILER_VERSION CHAISCRIPT_STRINGIZE_EXPANDED(_MSC_FULL_VER)
14#define CHAISCRIPT_MSVC _MSC_VER
15#define CHAISCRIPT_HAS_DECLSPEC
16
17static_assert(_MSC_FULL_VER >= 190024210, "Visual C++ 2015 Update 3 or later required");
18
19#else
20#define CHAISCRIPT_COMPILER_VERSION __VERSION__
21#endif
22
23#include <vector>
24
25#if defined( _LIBCPP_VERSION )
26#define CHAISCRIPT_LIBCPP
27#endif
28
29#if defined(_WIN32) || defined(__CYGWIN__)
30#define CHAISCRIPT_WINDOWS
31#endif
32
33#if defined(_WIN32)
34#if defined(__llvm__)
35#define CHAISCRIPT_COMPILER_NAME "clang(windows)"
36#elif defined(__GNUC__)
37#define CHAISCRIPT_COMPILER_NAME "gcc(mingw)"
38#else
39#define CHAISCRIPT_COMPILER_NAME "msvc"
40#endif
41#else
42#if defined(__llvm__)
43#define CHAISCRIPT_COMPILER_NAME "clang"
44#elif defined(__GNUC__)
45#define CHAISCRIPT_COMPILER_NAME "gcc"
46#else
47#define CHAISCRIPT_COMPILER_NAME "unknown"
48#endif
49#endif
50
51
52#if defined(__llvm__)
53#define CHAISCRIPT_CLANG
54#endif
55
56
57#ifdef CHAISCRIPT_HAS_DECLSPEC
58#define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport)
59#else
60#define CHAISCRIPT_MODULE_EXPORT extern "C"
61#endif
62
63#if defined(CHAISCRIPT_MSVC) || (defined(__GNUC__) && __GNUC__ >= 5) || defined(CHAISCRIPT_CLANG)
64#define CHAISCRIPT_UTF16_UTF32
65#endif
66
67#ifdef _DEBUG
68#define CHAISCRIPT_DEBUG true
69#else
70#define CHAISCRIPT_DEBUG false
71#endif
72
73#include <memory>
74#include <string>
75#include <cmath>
76
77namespace chaiscript {
78 static const int version_major = 6;
79 static const int version_minor = 1;
80 static const int version_patch = 0;
81
82 static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
83 static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
84 static const bool debug_build = CHAISCRIPT_DEBUG;
85
86 template<typename B, typename D, typename ...Arg>
87 inline std::shared_ptr<B> make_shared(Arg && ... arg)
88 {
89#ifdef CHAISCRIPT_USE_STD_MAKE_SHARED
90 return std::make_shared<D>(std::forward<Arg>(arg)...);
91#else
92 return std::shared_ptr<B>(static_cast<B*>(new D(std::forward<Arg>(arg)...)));
93#endif
94 }
95
96 template<typename B, typename D, typename ...Arg>
97 inline std::unique_ptr<B> make_unique(Arg && ... arg)
98 {
99#ifdef CHAISCRIPT_USE_STD_MAKE_SHARED
100 return std::make_unique<D>(std::forward<Arg>(arg)...);
101#else
102 return std::unique_ptr<B>(static_cast<B*>(new D(std::forward<Arg>(arg)...)));
103#endif
104 }
105
106 struct Build_Info {
107 static int version_major()
108 {
109 return chaiscript::version_major;
110 }
111
112 static int version_minor()
113 {
114 return chaiscript::version_minor;
115 }
116
117 static int version_patch()
118 {
119 return chaiscript::version_patch;
120 }
121
122 static std::string version()
123 {
124 return std::to_string(version_major()) + '.' + std::to_string(version_minor()) + '.' + std::to_string(version_patch());
125 }
126
127 static std::string compiler_id()
128 {
129 return compiler_name() + '-' + compiler_version();
130 }
131
132 static std::string build_id()
133 {
134 return compiler_id() + (debug_build()?"-Debug":"-Release");
135 }
136
137 static std::string compiler_version()
138 {
139 return chaiscript::compiler_version;
140 }
141
142 static std::string compiler_name()
143 {
144 return chaiscript::compiler_name;
145 }
146
147 static bool debug_build()
148 {
149 return chaiscript::debug_build;
150 }
151 };
152
153
154 template<typename T>
155 auto parse_num(const char *t_str) -> typename std::enable_if<std::is_integral<T>::value, T>::type
156 {
157 T t = 0;
158 for (char c = *t_str; (c = *t_str) != 0; ++t_str) {
159 if (c < '0' || c > '9') {
160 return t;
161 }
162 t *= 10;
163 t += c - '0';
164 }
165 return t;
166 }
167
168
169 template<typename T>
170 auto parse_num(const char *t_str) -> typename std::enable_if<!std::is_integral<T>::value, T>::type
171 {
172 T t = 0;
173 T base{};
174 T decimal_place = 0;
175 int exponent = 0;
176
177 for (char c;; ++t_str) {
178 c = *t_str;
179 switch (c)
180 {
181 case '.':
182 decimal_place = 10;
183 break;
184 case 'e':
185 case 'E':
186 exponent = 1;
187 decimal_place = 0;
188 base = t;
189 t = 0;
190 break;
191 case '-':
192 exponent = -1;
193 break;
194 case '+':
195 break;
196 case '0':
197 case '1':
198 case '2':
199 case '3':
200 case '4':
201 case '5':
202 case '6':
203 case '7':
204 case '8':
205 case '9':
206 if (decimal_place < 10) {
207 t *= 10;
208 t += static_cast<T>(c - '0');
209 }
210 else {
211 t += static_cast<T>(c - '0') / decimal_place;
212 decimal_place *= 10;
213 }
214 break;
215 default:
216 return exponent ? base * std::pow(T(10), t * static_cast<T>(exponent)) : t;
217 }
218 }
219 }
220
221 template<typename T>
222 T parse_num(const std::string &t_str)
223 {
224 return parse_num<T>(t_str.c_str());
225 }
226
234
235 static inline std::vector<Options> default_options()
236 {
237#ifdef CHAISCRIPT_NO_DYNLOAD
239#else
241#endif
242 }
243}
244#endif
245
float arg(Complex z)
Definition GameApi_pl.cc:31413
#define CHAISCRIPT_COMPILER_VERSION
Definition chaiscript_defines.hpp:20
#define CHAISCRIPT_COMPILER_NAME
Definition chaiscript_defines.hpp:47
#define CHAISCRIPT_DEBUG
Definition chaiscript_defines.hpp:70
Definition compiled_tests.cpp:1200
Namespace chaiscript contains every API call that the average user will be concerned with.
Options
Definition chaiscript_defines.hpp:228
@ No_External_Scripts
Definition chaiscript_defines.hpp:231
@ External_Scripts
Definition chaiscript_defines.hpp:232
@ No_Load_Modules
Definition chaiscript_defines.hpp:229
@ Load_Modules
Definition chaiscript_defines.hpp:230
std::unique_ptr< B > make_unique(Arg &&... arg)
Definition chaiscript_defines.hpp:97
std::shared_ptr< B > make_shared(Arg &&... arg)
Definition chaiscript_defines.hpp:87
auto parse_num(const char *t_str) -> typename std::enable_if< std::is_integral< T >::value, T >::type
Definition chaiscript_defines.hpp:155
@ Arg
Definition chaiscript_common.hpp:69
Definition GameApi.h:57
Definition GameApi.h:42
Definition chaiscript_defines.hpp:106
static std::string build_id()
Definition chaiscript_defines.hpp:132
static std::string compiler_id()
Definition chaiscript_defines.hpp:127
static bool debug_build()
Definition chaiscript_defines.hpp:147
static std::string compiler_name()
Definition chaiscript_defines.hpp:142
static std::string compiler_version()
Definition chaiscript_defines.hpp:137
static int version_major()
Definition chaiscript_defines.hpp:107
static int version_patch()
Definition chaiscript_defines.hpp:117
static std::string version()
Definition chaiscript_defines.hpp:122
static int version_minor()
Definition chaiscript_defines.hpp:112