mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
parent
2777b6ad15
commit
92f3330e03
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,8 @@
|
|||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2018-06-11 18:42:24.829810 UTC
|
// Generated 2018-06-15 19:50:08.054132 UTC
|
||||||
// This header was generated with sol v2.20.2 (revision ac70911)
|
// This header was generated with sol v2.20.2 (revision 2777b6a)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||||
@ -221,6 +221,10 @@
|
|||||||
|
|
||||||
// end of sol/config.hpp
|
// end of sol/config.hpp
|
||||||
|
|
||||||
|
// beginning of sol/config_setup.hpp
|
||||||
|
|
||||||
|
// end of sol/config_setup.hpp
|
||||||
|
|
||||||
// end of sol/feature_test.hpp
|
// end of sol/feature_test.hpp
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
@ -252,27 +252,44 @@ namespace stack {
|
|||||||
struct pusher<detail::as_table_tag<T>> {
|
struct pusher<detail::as_table_tag<T>> {
|
||||||
static int push(lua_State* L, const T& tablecont) {
|
static int push(lua_State* L, const T& tablecont) {
|
||||||
typedef meta::has_key_value_pair<meta::unqualified_t<std::remove_pointer_t<T>>> has_kvp;
|
typedef meta::has_key_value_pair<meta::unqualified_t<std::remove_pointer_t<T>>> has_kvp;
|
||||||
return push(has_kvp(), L, tablecont);
|
return push(has_kvp(), std::false_type(), L, tablecont);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int push(std::true_type, lua_State* L, const T& tablecont) {
|
static int push(std::true_type, lua_State* L, const T& tablecont) {
|
||||||
|
typedef meta::has_key_value_pair<meta::unqualified_t<std::remove_pointer_t<T>>> has_kvp;
|
||||||
|
return push(has_kvp(), std::true_type(), L, tablecont);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int push(std::false_type, lua_State* L, const T& tablecont) {
|
||||||
|
typedef meta::has_key_value_pair<meta::unqualified_t<std::remove_pointer_t<T>>> has_kvp;
|
||||||
|
return push(has_kvp(), std::false_type(), L, tablecont);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool is_nested>
|
||||||
|
static int push(std::true_type, std::integral_constant<bool, is_nested>, lua_State* L, const T& tablecont) {
|
||||||
auto& cont = detail::deref(detail::unwrap(tablecont));
|
auto& cont = detail::deref(detail::unwrap(tablecont));
|
||||||
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
||||||
int tableindex = lua_gettop(L);
|
int tableindex = lua_gettop(L);
|
||||||
for (const auto& pair : cont) {
|
for (const auto& pair : cont) {
|
||||||
|
if (is_nested) {
|
||||||
|
set_field(L, pair.first, as_nested_ref(pair.second), tableindex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
set_field(L, pair.first, pair.second, tableindex);
|
set_field(L, pair.first, pair.second, tableindex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int push(std::false_type, lua_State* L, const T& tablecont) {
|
template <bool is_nested>
|
||||||
|
static int push(std::false_type, std::integral_constant<bool, is_nested>, lua_State* L, const T& tablecont) {
|
||||||
auto& cont = detail::deref(detail::unwrap(tablecont));
|
auto& cont = detail::deref(detail::unwrap(tablecont));
|
||||||
lua_createtable(L, stack_detail::get_size_hint(cont), 0);
|
lua_createtable(L, stack_detail::get_size_hint(cont), 0);
|
||||||
int tableindex = lua_gettop(L);
|
int tableindex = lua_gettop(L);
|
||||||
std::size_t index = 1;
|
std::size_t index = 1;
|
||||||
for (const auto& i : cont) {
|
for (const auto& i : cont) {
|
||||||
#if SOL_LUA_VERSION >= 503
|
#if SOL_LUA_VERSION >= 503
|
||||||
int p = stack::push(L, i);
|
int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i);
|
||||||
for (int pi = 0; pi < p; ++pi) {
|
for (int pi = 0; pi < p; ++pi) {
|
||||||
lua_seti(L, tableindex, static_cast<lua_Integer>(index++));
|
lua_seti(L, tableindex, static_cast<lua_Integer>(index++));
|
||||||
}
|
}
|
||||||
@ -317,9 +334,19 @@ namespace stack {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct pusher<nested<T>> {
|
struct pusher<nested<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||||
static int push(lua_State* L, const T& tablecont) {
|
static int push(lua_State* L, const T& tablecont) {
|
||||||
pusher<as_table_t<T>> p{};
|
pusher<detail::as_table_tag<T>> p{};
|
||||||
|
// silence annoying VC++ warning
|
||||||
|
(void)p;
|
||||||
|
return p.push(std::true_type(), L, tablecont);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct pusher<nested<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||||
|
static int push(lua_State* L, const T& tablecont) {
|
||||||
|
pusher<meta::unqualified_t<T>> p{};
|
||||||
// silence annoying VC++ warning
|
// silence annoying VC++ warning
|
||||||
(void)p;
|
(void)p;
|
||||||
return p.push(L, tablecont);
|
return p.push(L, tablecont);
|
||||||
|
@ -346,6 +346,44 @@ TEST_CASE("containers/from table argument conversions", "test table conversions
|
|||||||
REQUIRE(passed);
|
REQUIRE(passed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("containers/deeply nested", "make sure nested works for deeply-nested C++ containers and works as advertised") {
|
||||||
|
typedef std::map<const char *, std::string> info_t;
|
||||||
|
typedef std::vector<info_t> info_vector;
|
||||||
|
|
||||||
|
class ModList {
|
||||||
|
public:
|
||||||
|
info_vector list;
|
||||||
|
|
||||||
|
ModList() {
|
||||||
|
list.push_back(info_t{
|
||||||
|
{"a", "b"}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sol::nested<info_vector> getList () {
|
||||||
|
return sol::nested<info_vector>(list);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
|
lua.new_usertype<ModList>("ModList",
|
||||||
|
"getList", &ModList::getList
|
||||||
|
);
|
||||||
|
|
||||||
|
sol::string_view code = R"(
|
||||||
|
mods = ModList.new()
|
||||||
|
local modlist = mods:getList()
|
||||||
|
print(modlist[1])
|
||||||
|
assert(type(modlist) == "table")
|
||||||
|
assert(type(modlist[1]) == "table")
|
||||||
|
)";
|
||||||
|
|
||||||
|
auto result1 = lua.safe_script(code, sol::script_pass_on_error);
|
||||||
|
REQUIRE(result1.valid());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("containers/vector roundtrip", "make sure vectors can be round-tripped") {
|
TEST_CASE("containers/vector roundtrip", "make sure vectors can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::vector<int> v{ 1, 2, 3 };
|
std::vector<int> v{ 1, 2, 3 };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user