get rid of public format_int/float (use cs_value)

master
Daniel Kolesa 2021-03-19 00:34:12 +01:00
parent 26bcc43578
commit af1a85fb91
2 changed files with 12 additions and 23 deletions

View File

@ -760,27 +760,6 @@ namespace util {
cs_state &cs, ostd::string_range str
);
template<typename R>
inline void format_int(R &&writer, cs_int val) {
try {
ostd::format(std::forward<R>(writer), CS_INT_FORMAT, val);
} catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()};
}
}
template<typename R>
inline void format_float(R &&writer, cs_float val) {
try {
ostd::format(
std::forward<R>(writer),
(val == floor(val)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, val
);
} catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()};
}
}
template<typename R>
inline void print_stack(R &&writer, cs_stack_state const &st) {
auto nd = st.get();

View File

@ -6,13 +6,23 @@ namespace cscript {
static cs_string intstr(cs_int v) {
auto app = ostd::appender<cs_string>();
cscript::util::format_int(app, v);
try {
ostd::format(app, CS_INT_FORMAT, v);
} catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()};
}
return std::move(app.get());
}
static cs_string floatstr(cs_float v) {
auto app = ostd::appender<cs_string>();
cscript::util::format_float(app, v);
try {
ostd::format(
app, (v == floor(v)) ? CS_ROUND_FLOAT_FORMAT : CS_FLOAT_FORMAT, v
);
} catch (ostd::format_error const &e) {
throw cs_internal_error{e.what()};
}
return std::move(app.get());
}