mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix up the pop<> behavior here...
This commit is contained in:
parent
22ecd349ab
commit
b77f1a2102
|
@ -1253,7 +1253,7 @@ namespace sol {
|
|||
|
||||
template <typename T>
|
||||
decltype(auto) pop(lua_State* L) {
|
||||
return popper<meta::unqualified_t<T>> {}.pop(L);
|
||||
return popper<T> {}.pop(L);
|
||||
}
|
||||
|
||||
template <bool global = false, bool raw = false, typename Key>
|
||||
|
@ -1318,13 +1318,12 @@ namespace sol {
|
|||
|
||||
template <typename T, typename F>
|
||||
void modify_unique_usertype_as(const stack_reference& obj, F&& f) {
|
||||
using u_traits = unique_usertype_traits<T>;
|
||||
void* raw = lua_touserdata(obj.lua_state(), obj.stack_index());
|
||||
void* ptr_memory = detail::align_usertype_pointer(raw);
|
||||
void* uu_memory = detail::align_usertype_unique<T>(raw);
|
||||
T& uu = *static_cast<T*>(uu_memory);
|
||||
f(uu);
|
||||
*static_cast<void**>(ptr_memory) = static_cast<void*>(u_traits::get(uu));
|
||||
*static_cast<void**>(ptr_memory) = static_cast<void*>(detail::unique_get(obj.lua_state(), uu));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2021-02-02 04:28:44.753067 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// Generated 2021-02-03 01:36:37.733271 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 22ecd349)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_CONFIG_HPP
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2021-02-02 04:28:44.742065 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// Generated 2021-02-03 01:36:37.666578 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 22ecd349)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2021-02-02 04:28:44.395065 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// Generated 2021-02-03 01:36:36.756148 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 22ecd349)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -11599,7 +11599,7 @@ namespace sol {
|
|||
|
||||
template <typename T>
|
||||
decltype(auto) pop(lua_State* L) {
|
||||
return popper<meta::unqualified_t<T>> {}.pop(L);
|
||||
return popper<T> {}.pop(L);
|
||||
}
|
||||
|
||||
template <bool global = false, bool raw = false, typename Key>
|
||||
|
@ -11664,13 +11664,12 @@ namespace sol {
|
|||
|
||||
template <typename T, typename F>
|
||||
void modify_unique_usertype_as(const stack_reference& obj, F&& f) {
|
||||
using u_traits = unique_usertype_traits<T>;
|
||||
void* raw = lua_touserdata(obj.lua_state(), obj.stack_index());
|
||||
void* ptr_memory = detail::align_usertype_pointer(raw);
|
||||
void* uu_memory = detail::align_usertype_unique<T>(raw);
|
||||
T& uu = *static_cast<T*>(uu_memory);
|
||||
f(uu);
|
||||
*static_cast<void**>(ptr_memory) = static_cast<void*>(u_traits::get(uu));
|
||||
*static_cast<void**>(ptr_memory) = static_cast<void*>(detail::unique_get(obj.lua_state(), uu));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
|
|
|
@ -31,27 +31,36 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
bool func_opt_ret_bool(sol::optional<int> i) {
|
||||
if (i) {
|
||||
INFO(i.value());
|
||||
inline namespace sol2_tests_basic {
|
||||
|
||||
bool func_opt_ret_bool(sol::optional<int> i) {
|
||||
if (i) {
|
||||
INFO(i.value());
|
||||
}
|
||||
else {
|
||||
INFO("optional isn't set");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
INFO("optional isn't set");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct base1 {
|
||||
int a1 = 250;
|
||||
};
|
||||
struct base1 {
|
||||
int a1 = 250;
|
||||
};
|
||||
|
||||
struct base2 {
|
||||
int a2 = 500;
|
||||
};
|
||||
struct base2 {
|
||||
int a2 = 500;
|
||||
};
|
||||
|
||||
struct simple : base1 { };
|
||||
struct simple : base1 { };
|
||||
|
||||
struct complex : base1, base2 { };
|
||||
struct complex : base1, base2 { };
|
||||
|
||||
struct CardAction {
|
||||
int value;
|
||||
};
|
||||
|
||||
|
||||
} // namespace sol2_tests_basic
|
||||
|
||||
SOL_BASE_CLASSES(complex, base1, base2);
|
||||
SOL_BASE_CLASSES(simple, base1);
|
||||
|
@ -707,3 +716,14 @@ TEST_CASE("object/base_of_things", "make sure that object is the base of things
|
|||
REQUIRE(result6.valid());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("object/pop-based reference conversions", "Make sure conversions going through .as<T>() also have support for reference") {
|
||||
sol::state lua;
|
||||
|
||||
lua["on_execute_impl"] = []() { return std::make_unique<CardAction>(CardAction { 5 }); };
|
||||
|
||||
sol::object obj = lua["on_execute_impl"]();
|
||||
REQUIRE(obj.valid());
|
||||
auto& ptr = obj.as<std::unique_ptr<CardAction>&>();
|
||||
REQUIRE(ptr->value == 5);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user