mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
add new tests for unqualified returns through as_nested/as_table
This commit is contained in:
parent
b544a43734
commit
732b4bd700
|
@ -93,7 +93,7 @@ Please make sure you use the `-std=c++1y`, `-std=c++14`, `-std=c++1z`, `-std=c++
|
|||
Older compilers (GCC 4.9.x, Clang 3.4.x seem to be the lowest) can work with versions as late
|
||||
as [v2.17.5](https://github.com/ThePhD/sol2/releases/tag/v2.17.5), with the flag `-std=c++14` or `-std=c++1y`.
|
||||
|
||||
Is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags.
|
||||
sol2 is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags.
|
||||
|
||||
## Running the Tests
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ matrix:
|
|||
- platform: x86
|
||||
LLVM_VERSION: 4.0.0
|
||||
# Get rid of x86 builds
|
||||
- platform: x86
|
||||
image: Visual Studio 2015
|
||||
- platform: x86
|
||||
LUA_VERSION: 5.2.4
|
||||
- platform: x86
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
} while (false)
|
||||
#else
|
||||
# define m_assert(condition, message) do { if (false) { (void)(condition); (void)sizeof(message); } } while (false)
|
||||
# define c_assert(condition) do { (void)sizeof(condition); } while (false)
|
||||
# define c_assert(condition) do { if (false) { (void)(condition); } } while (false)
|
||||
#endif
|
||||
|
||||
#endif // EXAMPLES_ASSERT_HPP
|
||||
|
|
|
@ -508,15 +508,25 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
as_table_t<T> as_table(T&& container) {
|
||||
as_table_t<T> as_table_ref(T&& container) {
|
||||
return as_table_t<T>(std::forward<T>(container));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
nested<T> as_nested(T&& container) {
|
||||
as_table_t<meta::unqualified_t<T>> as_table(T&& container) {
|
||||
return as_table_t<meta::unqualified_t<T>>(std::forward<T>(container));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
nested<T> as_nested_ref(T&& container) {
|
||||
return nested<T>(std::forward<T>(container));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
nested<meta::unqualified_t<T>> as_nested(T&& container) {
|
||||
return nested<meta::unqualified_t<T>>(std::forward<T>(container));
|
||||
}
|
||||
|
||||
struct this_state {
|
||||
lua_State* L;
|
||||
|
||||
|
|
|
@ -196,6 +196,86 @@ TEST_CASE("containers/returns", "make sure that even references to vectors are b
|
|||
REQUIRE(matching);
|
||||
}
|
||||
|
||||
TEST_CASE("containers/table conversions (lvalue)", "test table conversions with as_table and nested, when not directly serializing a temporary / new value") {
|
||||
sol::state lua;
|
||||
|
||||
auto f = []() {
|
||||
std::vector<std::string> response_words;
|
||||
response_words.push_back("a");
|
||||
response_words.push_back("b");
|
||||
response_words.push_back("c");
|
||||
return sol::as_table(response_words);
|
||||
};
|
||||
auto g = []() {
|
||||
std::vector<std::string> response_words;
|
||||
response_words.push_back("a");
|
||||
response_words.push_back("b");
|
||||
response_words.push_back("c");
|
||||
return sol::as_nested(response_words);
|
||||
};
|
||||
|
||||
lua["f"] = std::ref(f);
|
||||
lua["g"] = std::ref(g);
|
||||
|
||||
sol::safe_function sff = lua["f"];
|
||||
sol::safe_function sfg = lua["g"];
|
||||
sol::table tf = sff();
|
||||
sol::table tg = sfg();
|
||||
|
||||
std::string af = tf[1];
|
||||
std::string bf = tf[2];
|
||||
std::string cf = tf[3];
|
||||
std::string ag = tf[1];
|
||||
std::string bg = tf[2];
|
||||
std::string cg = tf[3];
|
||||
REQUIRE(tf.size() == 3);
|
||||
REQUIRE(af == "a");
|
||||
REQUIRE(bf == "b");
|
||||
REQUIRE(cf == "c");
|
||||
REQUIRE(tg.size() == 3);
|
||||
REQUIRE(ag == "a");
|
||||
REQUIRE(bg == "b");
|
||||
REQUIRE(cg == "c");
|
||||
}
|
||||
|
||||
TEST_CASE("containers/table conversions (std::ref)", "test table conversions with as_table and nested, when not directly serializing a temporary / new value") {
|
||||
sol::state lua;
|
||||
|
||||
std::vector<std::string> response_words;
|
||||
response_words.push_back("a");
|
||||
response_words.push_back("b");
|
||||
response_words.push_back("c");
|
||||
auto f = [&response_words]() {
|
||||
return sol::as_table(std::ref(response_words));
|
||||
};
|
||||
auto g = [&response_words]() {
|
||||
return sol::as_nested(std::ref(response_words));
|
||||
};
|
||||
|
||||
lua["f"] = std::ref(f);
|
||||
lua["g"] = std::ref(g);
|
||||
|
||||
sol::safe_function sff = lua["f"];
|
||||
sol::safe_function sfg = lua["g"];
|
||||
sol::table tf = sff();
|
||||
sol::table tg = sfg();
|
||||
|
||||
std::string af = tf[1];
|
||||
std::string bf = tf[2];
|
||||
std::string cf = tf[3];
|
||||
std::string ag = tf[1];
|
||||
std::string bg = tf[2];
|
||||
std::string cg = tf[3];
|
||||
REQUIRE(tf.size() == 3);
|
||||
REQUIRE(af == "a");
|
||||
REQUIRE(bf == "b");
|
||||
REQUIRE(cf == "c");
|
||||
REQUIRE(tg.size() == 3);
|
||||
REQUIRE(ag == "a");
|
||||
REQUIRE(bg == "b");
|
||||
REQUIRE(cg == "c");
|
||||
}
|
||||
|
||||
TEST_CASE("containers/table conversion", "test table conversions with as_table and nested") {
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
|
|
Loading…
Reference in New Issue
Block a user