diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 9747c3b..4c24ced 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -305,7 +306,7 @@ protected: alias() = default; }; -struct command: ident { +struct LIBCUBESCRIPT_EXPORT command: ident { std::string_view get_args() const; int get_num_args() const; @@ -354,18 +355,18 @@ struct LIBCUBESCRIPT_EXPORT state { template hook_func set_call_hook(F &&f) { - return std::move(set_call_hook( + return set_call_hook( hook_func{std::forward(f), callable_alloc, this} - )); + ); } hook_func const &get_call_hook() const; hook_func &get_call_hook(); template var_print_func set_var_printer(F &&f) { - return std::move(set_var_printer( + return set_var_printer( var_print_func{std::forward(f), callable_alloc, this} - )); + ); } var_print_func const &get_var_printer() const; @@ -532,7 +533,7 @@ private: thread_state *p_tstate = nullptr; }; -struct stack_state { +struct LIBCUBESCRIPT_EXPORT stack_state { struct node { node const *next; ident const *id; diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 8b4ce1f..25e88a7 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -706,7 +706,7 @@ static bool compilearg( } case VAL_WORD: if (word) { - *word = std::move(gs.get_str_dup()); + *word = gs.get_str_dup(); } break; case VAL_ANY: diff --git a/src/cs_parser.cc b/src/cs_parser.cc index b86b6ec..faf22e0 100644 --- a/src/cs_parser.cc +++ b/src/cs_parser.cc @@ -2,6 +2,7 @@ #include #include +#include #include "cs_std.hh" #include "cs_thread.hh" @@ -18,8 +19,8 @@ LIBCUBESCRIPT_EXPORT char const *parse_string( if (str.empty() || (str.front() != '\"')) { return str.data(); } - char const *beg = str.begin(); - char const *end = str.end(); + char const *beg = &str[0]; + char const *end = &str[str.size()]; char const *orig = beg++; ++nl; while (beg != end) { @@ -66,8 +67,8 @@ end: LIBCUBESCRIPT_EXPORT char const *parse_word( state &cs, std::string_view str ) { - char const *it = str.begin(); - char const *end = str.end(); + char const *it = &str[0]; + char const *end = &str[str.size()]; for (; it != end; ++it) { std::string_view chrs{"\"/;()[] \t\r\n"}; it = std::find_first_of(it, end, chrs.begin(), chrs.end()); @@ -148,8 +149,8 @@ static inline bool p_check_neg(char const *&input) { } integer_type parse_int(std::string_view input, std::string_view *endstr) { - char const *beg = input.begin(); - char const *end = input.end(); + char const *beg = &input[0]; + char const *end = &input[input.size()]; char const *orig = beg; beg = p_skip_white(beg, end); if (beg == end) { @@ -256,8 +257,8 @@ static inline bool parse_gen_float( } float_type parse_float(std::string_view input, std::string_view *endstr) { - char const *beg = input.begin(); - char const *end = input.end(); + char const *beg = &input[0]; + char const *end = &input[input.size()]; char const *orig = beg; beg = p_skip_white(beg, end); if (beg == end) { diff --git a/src/cs_val.cc b/src/cs_val.cc index 9b31fe9..f5dab58 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -5,6 +5,7 @@ #include "cs_state.hh" #include +#include namespace cubescript { @@ -191,7 +192,7 @@ float_type any_value::force_float() { float_type rf = 0.0f; switch (get_type()) { case value_type::INT: - rf = csv_get(&p_stor); + rf = float_type(csv_get(&p_stor)); break; case value_type::STRING: rf = parse_float( @@ -211,7 +212,7 @@ integer_type any_value::force_int() { integer_type ri = 0; switch (get_type()) { case value_type::FLOAT: - ri = csv_get(&p_stor); + ri = integer_type(std::floor(csv_get(&p_stor))); break; case value_type::STRING: ri = parse_int( diff --git a/src/lib_base.cc b/src/lib_base.cc index 7958268..72fbe11 100644 --- a/src/lib_base.cc +++ b/src/lib_base.cc @@ -1,5 +1,7 @@ #include +#include + #include "cs_std.hh" #include "cs_ident.hh" diff --git a/src/lib_math.cc b/src/lib_math.cc index 6d908fd..5ef4716 100644 --- a/src/lib_math.cc +++ b/src/lib_math.cc @@ -8,8 +8,9 @@ namespace cubescript { -static constexpr float_type PI = 3.14159265358979f; -static constexpr float_type RAD = PI / 180.0f; +static constexpr float_type PI = float_type(3.14159265358979323846); +static constexpr float_type LN2 = float_type(0.693147180559945309417); +static constexpr float_type RAD = PI / float_type(180.0); template struct math_val; @@ -103,7 +104,7 @@ void init_lib_math(state &cs) { res.set_float(std::log(args[0].get_float())); }); cs.new_command("log2", "f", [](auto &, auto args, auto &res) { - res.set_float(std::log(args[0].get_float()) / M_LN2); + res.set_float(std::log(args[0].get_float()) / LN2); }); cs.new_command("log10", "f", [](auto &, auto args, auto &res) { res.set_float(std::log10(args[0].get_float())); diff --git a/src/lib_str.cc b/src/lib_str.cc index c7ee07b..69dde3c 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -198,7 +198,6 @@ void init_lib_string(state &cs) { } charbuf buf{ccs}; for (size_t i = 0;; ++i) { - std::string_view found; auto p = s.find(oldval); if (p == s.npos) { buf.append(s); diff --git a/src/meson.build b/src/meson.build index 14eeac6..399a11a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -21,10 +21,20 @@ libcubescript_src = [ 'lib_str.cc' ] +lib_cxxflags = [] +host_system = host_machine.system() + +if host_system == 'windows' or host_system == 'cygwin' + lib_cxxflags += '-DLIBCUBESCRIPT_BUILD' + if get_option('default_library') != 'static' + lib_cxxflags += '-DLIBCUBESCRIPT_DLL' + endif +endif + libcubescript_target = library('cubescript', libcubescript_src, include_directories: libcubescript_includes + [include_directories('.')], - cpp_args: extra_cxxflags, + cpp_args: extra_cxxflags + lib_cxxflags, install: true, pic: true, version: meson.project_version() diff --git a/tools/repl.cc b/tools/repl.cc index 40428b5..7250e57 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -1,6 +1,12 @@ +/* avoid silly complaints about fopen */ +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS 1 +#endif + #include #include +#include #include #include #include @@ -183,9 +189,9 @@ static cs::state *scs = nullptr; static void do_sigint(int n) { /* in case another SIGINT happens, terminate normally */ signal(n, SIG_DFL); - scs->set_call_hook([](cs::state &cs) { - cs.set_call_hook(nullptr); - throw cs::error{cs, ""}; + scs->set_call_hook([](cs::state &css) { + css.set_call_hook(nullptr); + throw cs::error{css, ""}; }); } @@ -355,13 +361,13 @@ int main(int argc, char **argv) { gcs.set_var_printer(repl_print_var); gcs.init_libs(); - gcs.new_command("exec", "s", [](auto &cs, auto args, auto &) { + gcs.new_command("exec", "s", [](auto &css, auto args, auto &) { auto file = args[0].get_str(); - cs::any_value val{cs}; - bool ret = do_run_file(cs, file, val); + cs::any_value val{css}; + bool ret = do_run_file(css, file, val); if (!ret) { throw cs::error( - cs, "could not run file \"%s\"", file + css, "could not run file \"%s\"", file.data() ); } });