From f1ff3d6492d95105aaf0dea83f42b05f349c9019 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 7 Aug 2017 07:54:43 -0400 Subject: [PATCH] improve tests change the default chunk name (and make it trail off if chunk name is too small) minor changes to appease g++'s and clang++'s many warnings --- sol/container_traits.hpp | 4 ++-- sol/stack.hpp | 7 ++++++- sol/state_view.hpp | 4 ++++ test_container_semantics.cpp | 4 ++-- test_containers.cpp | 4 ++-- test_variadics.cpp | 6 +++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sol/container_traits.hpp b/sol/container_traits.hpp index 8cbc4198..f94f0659 100644 --- a/sol/container_traits.hpp +++ b/sol/container_traits.hpp @@ -1073,7 +1073,7 @@ namespace sol { static int get(lua_State* L) { T& self = get_src(L); std::ptrdiff_t idx = stack::get(L, 2); - if (idx > std::extent::value || idx < 1) { + if (idx > static_cast(std::extent::value) || idx < 1) { return stack::push(L, lua_nil); } --idx; @@ -1087,7 +1087,7 @@ namespace sol { static int set(lua_State* L) { T& self = get_src(L); std::ptrdiff_t idx = stack::get(L, 2); - if (idx > std::extent::value) { + if (idx > static_cast(std::extent::value)) { return luaL_error(L, "sol: index out of bounds (too big) for set on '%s'", detail::demangle().c_str()); } if (idx < 1) { diff --git a/sol/stack.hpp b/sol/stack.hpp index 7f81cbd6..538751c4 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -47,10 +47,15 @@ namespace sol { auto it = code.cbegin(); auto e = code.cend(); std::size_t i = 0; - static const std::size_t n = N - 1; + static const std::size_t n = N - 4; for (i = 0; i < n && it != e; ++i, ++it) { basechunkname[i] = *it; } + if (it != e) { + for (std::size_t c = 0; c < 3; ++i, ++c) { + basechunkname[i] = "."; + } + } basechunkname[i] = '\0'; return &basechunkname[0]; } diff --git a/sol/state_view.hpp b/sol/state_view.hpp index 12a9beeb..33d35db5 100644 --- a/sol/state_view.hpp +++ b/sol/state_view.hpp @@ -458,7 +458,11 @@ namespace sol { load_result load(lua_Reader reader, void* data, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) { char basechunkname[17] = {}; const char* chunknametarget = detail::make_chunk_name("lua_reader", chunkname, basechunkname); +#if SOL_LUA_VERSION > 501 load_status x = static_cast(lua_load(L, reader, data, chunknametarget, to_string(mode).c_str())); +#else + load_status x = static_cast(lua_load(L, reader, data, chunknametarget)); +#endif return load_result(L, absolute_index(L, -1), 1, 1, x); } diff --git a/test_container_semantics.cpp b/test_container_semantics.cpp index 65fb18e2..860fc84c 100644 --- a/test_container_semantics.cpp +++ b/test_container_semantics.cpp @@ -681,7 +681,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") { sol::state lua; lua.open_libraries(sol::lib::base); - std::array items{ 11, 12, 13, 14, 15 }; + std::array items{ { 11, 12, 13, 14, 15 } }; lua["c"] = &items; fixed_container_check(lua, items); } @@ -689,7 +689,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") { sol::state lua; lua.open_libraries(sol::lib::base); - std::array items{ 11, 12, 13, 14, 15 }; + std::array items{ { 11, 12, 13, 14, 15 } }; lua["c"] = std::ref(items); fixed_container_check(lua, items); } diff --git a/test_containers.cpp b/test_containers.cpp index 938832c3..2b562b2d 100644 --- a/test_containers.cpp +++ b/test_containers.cpp @@ -99,7 +99,7 @@ TEST_CASE("containers/deque roundtrip", "make sure deques can be round-tripped") TEST_CASE("containers/array roundtrip", "make sure arrays can be round-tripped") { sol::state lua; - std::array v{ 1, 2, 3 }; + std::array v{ { 1, 2, 3 } }; lua.set_function("f", [&]() -> std::array& { return v; }); @@ -207,7 +207,7 @@ TEST_CASE("containers/deque table roundtrip", "make sure deques can be round-tri TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tripped") { sol::state lua; - std::array v{ 1, 2, 3 }; + std::array v{ { 1, 2, 3 } }; lua.set_function("f", [&]() { return sol::as_table(v); }); diff --git a/test_variadics.cpp b/test_variadics.cpp index 75b0ff11..ce26baa8 100644 --- a/test_variadics.cpp +++ b/test_variadics.cpp @@ -182,15 +182,15 @@ TEST_CASE("variadics/variadic_results", "returning a variable amount of argument } TEST_CASE("variadics/fallback_constructor", "ensure constructor matching behaves properly in the presence of variadic fallbacks") { - struct vec2 { float x, y; }; + struct vec2 { float x = 0, y = 0; }; sol::state lua; lua.new_simple_usertype("vec2", sol::call_constructor, sol::factories([]() { return vec2{}; - }, [](vec2 const& v) { - return vec2{ v }; + }, [](vec2 const& v) -> vec2 { + return v; }, [](sol::variadic_args va) { vec2 res{}; if (va.size() == 1) {