mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
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
This commit is contained in:
parent
b86d90f0e5
commit
f1ff3d6492
|
@ -1073,7 +1073,7 @@ namespace sol {
|
||||||
static int get(lua_State* L) {
|
static int get(lua_State* L) {
|
||||||
T& self = get_src(L);
|
T& self = get_src(L);
|
||||||
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
|
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
|
||||||
if (idx > std::extent<T>::value || idx < 1) {
|
if (idx > static_cast<std::ptrdiff_t>(std::extent<T>::value) || idx < 1) {
|
||||||
return stack::push(L, lua_nil);
|
return stack::push(L, lua_nil);
|
||||||
}
|
}
|
||||||
--idx;
|
--idx;
|
||||||
|
@ -1087,7 +1087,7 @@ namespace sol {
|
||||||
static int set(lua_State* L) {
|
static int set(lua_State* L) {
|
||||||
T& self = get_src(L);
|
T& self = get_src(L);
|
||||||
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
|
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
|
||||||
if (idx > std::extent<T>::value) {
|
if (idx > static_cast<std::ptrdiff_t>(std::extent<T>::value)) {
|
||||||
return luaL_error(L, "sol: index out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
|
return luaL_error(L, "sol: index out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
|
||||||
}
|
}
|
||||||
if (idx < 1) {
|
if (idx < 1) {
|
||||||
|
|
|
@ -47,10 +47,15 @@ namespace sol {
|
||||||
auto it = code.cbegin();
|
auto it = code.cbegin();
|
||||||
auto e = code.cend();
|
auto e = code.cend();
|
||||||
std::size_t i = 0;
|
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) {
|
for (i = 0; i < n && it != e; ++i, ++it) {
|
||||||
basechunkname[i] = *it;
|
basechunkname[i] = *it;
|
||||||
}
|
}
|
||||||
|
if (it != e) {
|
||||||
|
for (std::size_t c = 0; c < 3; ++i, ++c) {
|
||||||
|
basechunkname[i] = ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
basechunkname[i] = '\0';
|
basechunkname[i] = '\0';
|
||||||
return &basechunkname[0];
|
return &basechunkname[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
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] = {};
|
char basechunkname[17] = {};
|
||||||
const char* chunknametarget = detail::make_chunk_name("lua_reader", chunkname, basechunkname);
|
const char* chunknametarget = detail::make_chunk_name("lua_reader", chunkname, basechunkname);
|
||||||
|
#if SOL_LUA_VERSION > 501
|
||||||
load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget, to_string(mode).c_str()));
|
load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget, to_string(mode).c_str()));
|
||||||
|
#else
|
||||||
|
load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget));
|
||||||
|
#endif
|
||||||
return load_result(L, absolute_index(L, -1), 1, 1, x);
|
return load_result(L, absolute_index(L, -1), 1, 1, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -681,7 +681,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.open_libraries(sol::lib::base);
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
std::array<int, 5> items{ 11, 12, 13, 14, 15 };
|
std::array<int, 5> items{ { 11, 12, 13, 14, 15 } };
|
||||||
lua["c"] = &items;
|
lua["c"] = &items;
|
||||||
fixed_container_check(lua, items);
|
fixed_container_check(lua, items);
|
||||||
}
|
}
|
||||||
|
@ -689,7 +689,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.open_libraries(sol::lib::base);
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
std::array<int, 5> items{ 11, 12, 13, 14, 15 };
|
std::array<int, 5> items{ { 11, 12, 13, 14, 15 } };
|
||||||
lua["c"] = std::ref(items);
|
lua["c"] = std::ref(items);
|
||||||
fixed_container_check(lua, items);
|
fixed_container_check(lua, items);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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") {
|
TEST_CASE("containers/array roundtrip", "make sure arrays can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::array<int, 3> v{ 1, 2, 3 };
|
std::array<int, 3> v{ { 1, 2, 3 } };
|
||||||
lua.set_function("f", [&]() -> std::array<int, 3>& {
|
lua.set_function("f", [&]() -> std::array<int, 3>& {
|
||||||
return v;
|
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") {
|
TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::array<int, 3> v{ 1, 2, 3 };
|
std::array<int, 3> v{ { 1, 2, 3 } };
|
||||||
lua.set_function("f", [&]() {
|
lua.set_function("f", [&]() {
|
||||||
return sol::as_table(v);
|
return sol::as_table(v);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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") {
|
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;
|
sol::state lua;
|
||||||
|
|
||||||
lua.new_simple_usertype<vec2>("vec2",
|
lua.new_simple_usertype<vec2>("vec2",
|
||||||
sol::call_constructor, sol::factories([]() {
|
sol::call_constructor, sol::factories([]() {
|
||||||
return vec2{};
|
return vec2{};
|
||||||
}, [](vec2 const& v) {
|
}, [](vec2 const& v) -> vec2 {
|
||||||
return vec2{ v };
|
return v;
|
||||||
}, [](sol::variadic_args va) {
|
}, [](sol::variadic_args va) {
|
||||||
vec2 res{};
|
vec2 res{};
|
||||||
if (va.size() == 1) {
|
if (va.size() == 1) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user