ditch cs_string from public headers + style fix

master
Daniel Kolesa 2021-03-18 23:56:16 +01:00
parent 9d0494a9da
commit d3ec4a47dd
4 changed files with 9 additions and 7 deletions

View File

@ -19,8 +19,6 @@
namespace cscript { namespace cscript {
using cs_string = std::string;
static_assert(std::is_integral_v<cs_int>, "cs_int must be integral"); static_assert(std::is_integral_v<cs_int>, "cs_int must be integral");
static_assert(std::is_signed_v<cs_int>, "cs_int must be signed"); static_assert(std::is_signed_v<cs_int>, "cs_int must be signed");
static_assert(std::is_floating_point_v<cs_float>, "cs_float must be floating point"); static_assert(std::is_floating_point_v<cs_float>, "cs_float must be floating point");
@ -761,7 +759,7 @@ namespace util {
template<typename R> template<typename R>
inline void format_int(R &&writer, cs_int val) { inline void format_int(R &&writer, cs_int val) {
try { try {
ostd::format(std::forward<R>(writer), IntFormat, val); ostd::format(std::forward<R>(writer), CS_INT_FORMAT, val);
} catch (ostd::format_error const &e) { } catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()}; throw cs_internal_error{e.what()};
} }
@ -772,7 +770,7 @@ namespace util {
try { try {
ostd::format( ostd::format(
std::forward<R>(writer), std::forward<R>(writer),
(val == cs_int(val)) ? RoundFloatFormat : FloatFormat, val (val == floor(val)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, val
); );
} catch (ostd::format_error const &e) { } catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()}; throw cs_internal_error{e.what()};

View File

@ -37,9 +37,9 @@ namespace cscript {
using cs_hook_cb = std::function<void(cs_state &)>; using cs_hook_cb = std::function<void(cs_state &)>;
using cs_alloc_cb = void *(*)(void *, void *, size_t, size_t); using cs_alloc_cb = void *(*)(void *, void *, size_t, size_t);
constexpr auto const IntFormat = "%d"; constexpr auto const CS_INT_FORMAT = "%d";
constexpr auto const FloatFormat = "%.7g"; constexpr auto const CS_FLOAT_FORMAT = "%.7g";
constexpr auto const RoundFloatFormat = "%.1f"; constexpr auto const CS_ROUND_FLOAT_FORMAT = "%.1f";
} /* namespace cscript */ } /* namespace cscript */
#endif /* LIBCUBESCRIPT_CUBESCRIPT_CONF_HH */ #endif /* LIBCUBESCRIPT_CUBESCRIPT_CONF_HH */

View File

@ -14,6 +14,8 @@ using cs_map = std::unordered_map<K, V>;
template<typename T> template<typename T>
using cs_vector = std::vector<T>; using cs_vector = std::vector<T>;
using cs_string = std::string;
cs_int cs_parse_int( cs_int cs_parse_int(
ostd::string_range input, ostd::string_range *end = nullptr ostd::string_range input, ostd::string_range *end = nullptr
); );

View File

@ -2,6 +2,8 @@
#include <cubescript/cubescript.hh> #include <cubescript/cubescript.hh>
#include "cs_util.hh"
namespace cscript { namespace cscript {
template<typename F> template<typename F>