mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
NOW it's REALLY fixed, super duperly.
This commit is contained in:
parent
e60a628e16
commit
e8649d276b
|
@ -250,13 +250,29 @@ namespace sol {
|
||||||
namespace stack {
|
namespace stack {
|
||||||
template <typename... Sigs>
|
template <typename... Sigs>
|
||||||
struct unqualified_pusher<function_sig<Sigs...>> {
|
struct unqualified_pusher<function_sig<Sigs...>> {
|
||||||
|
template <bool is_yielding, typename Arg0, typename... Args>
|
||||||
|
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
||||||
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<Arg0>, std::function>) {
|
||||||
|
if constexpr (is_yielding) {
|
||||||
|
return stack::push<meta::unqualified_t<Arg0>>(L, detail::yield_tag, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return stack::push(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<is_yielding>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Arg0, typename... Args>
|
template <typename Arg0, typename... Args>
|
||||||
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
||||||
if constexpr (std::is_same_v<meta::unqualified_t<Arg0>, detail::yield_tag_t>) {
|
if constexpr (std::is_same_v<meta::unqualified_t<Arg0>, detail::yield_tag_t>) {
|
||||||
function_detail::select<true>(L, std::forward<Args>(args)...);
|
push<true>(L, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
function_detail::select<false>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
push<false>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -266,14 +282,24 @@ namespace sol {
|
||||||
struct unqualified_pusher<yielding_t<T>> {
|
struct unqualified_pusher<yielding_t<T>> {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
|
static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
|
||||||
function_detail::select<true>(L, f.func, std::forward<Args>(args)...);
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<T>, std::function>) {
|
||||||
return 1;
|
return stack::push<T>(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<true>(L, f.func, std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
|
static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
|
||||||
function_detail::select<true>(L, std::move(f.func), std::forward<Args>(args)...);
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<T>, std::function>) {
|
||||||
return 1;
|
return stack::push<T>(L, detail::yield_tag, std::move(f.func), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<true>(L, std::move(f.func), std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -295,6 +321,22 @@ namespace sol {
|
||||||
|
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
struct unqualified_pusher<std::function<Signature>> {
|
struct unqualified_pusher<std::function<Signature>> {
|
||||||
|
static int push(lua_State* L, detail::yield_tag_t, const std::function<Signature>& fx) {
|
||||||
|
if (fx) {
|
||||||
|
function_detail::select<true>(L, fx);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stack::push(L, lua_nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int push(lua_State* L, detail::yield_tag_t, std::function<Signature>&& fx) {
|
||||||
|
if (fx) {
|
||||||
|
function_detail::select<true>(L, std::move(fx));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stack::push(L, lua_nil);
|
||||||
|
}
|
||||||
|
|
||||||
static int push(lua_State* L, const std::function<Signature>& fx) {
|
static int push(lua_State* L, const std::function<Signature>& fx) {
|
||||||
if (fx) {
|
if (fx) {
|
||||||
function_detail::select<false>(L, fx);
|
function_detail::select<false>(L, fx);
|
||||||
|
|
|
@ -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 2019-08-28 00:04:12.272016 UTC
|
// Generated 2019-08-28 04:16:59.509251 UTC
|
||||||
// This header was generated with sol v3.0.3 (revision a2e01ad)
|
// This header was generated with sol (revision )
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||||
|
|
|
@ -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 2019-08-28 00:04:08.251517 UTC
|
// Generated 2019-08-28 04:16:58.879902 UTC
|
||||||
// This header was generated with sol v3.0.3 (revision a2e01ad)
|
// This header was generated with sol (revision )
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -17860,13 +17860,29 @@ namespace sol {
|
||||||
namespace stack {
|
namespace stack {
|
||||||
template <typename... Sigs>
|
template <typename... Sigs>
|
||||||
struct unqualified_pusher<function_sig<Sigs...>> {
|
struct unqualified_pusher<function_sig<Sigs...>> {
|
||||||
|
template <bool is_yielding, typename Arg0, typename... Args>
|
||||||
|
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
||||||
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<Arg0>, std::function>) {
|
||||||
|
if constexpr (is_yielding) {
|
||||||
|
return stack::push<meta::unqualified_t<Arg0>>(L, detail::yield_tag, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return stack::push(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<is_yielding>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Arg0, typename... Args>
|
template <typename Arg0, typename... Args>
|
||||||
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
static int push(lua_State* L, Arg0&& arg0, Args&&... args) {
|
||||||
if constexpr (std::is_same_v<meta::unqualified_t<Arg0>, detail::yield_tag_t>) {
|
if constexpr (std::is_same_v<meta::unqualified_t<Arg0>, detail::yield_tag_t>) {
|
||||||
function_detail::select<true>(L, std::forward<Args>(args)...);
|
push<true>(L, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
function_detail::select<false>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
push<false>(L, std::forward<Arg0>(arg0), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -17876,14 +17892,24 @@ namespace sol {
|
||||||
struct unqualified_pusher<yielding_t<T>> {
|
struct unqualified_pusher<yielding_t<T>> {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
|
static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
|
||||||
function_detail::select<true>(L, f.func, std::forward<Args>(args)...);
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<T>, std::function>) {
|
||||||
return 1;
|
return stack::push<T>(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<true>(L, f.func, std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
|
static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
|
||||||
function_detail::select<true>(L, std::move(f.func), std::forward<Args>(args)...);
|
if constexpr (meta::is_specialization_of_v<meta::unqualified_t<T>, std::function>) {
|
||||||
return 1;
|
return stack::push<T>(L, detail::yield_tag, std::move(f.func), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
function_detail::select<true>(L, std::move(f.func), std::forward<Args>(args)...);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17905,6 +17931,22 @@ namespace sol {
|
||||||
|
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
struct unqualified_pusher<std::function<Signature>> {
|
struct unqualified_pusher<std::function<Signature>> {
|
||||||
|
static int push(lua_State* L, detail::yield_tag_t, const std::function<Signature>& fx) {
|
||||||
|
if (fx) {
|
||||||
|
function_detail::select<true>(L, fx);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stack::push(L, lua_nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int push(lua_State* L, detail::yield_tag_t, std::function<Signature>&& fx) {
|
||||||
|
if (fx) {
|
||||||
|
function_detail::select<true>(L, std::move(fx));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stack::push(L, lua_nil);
|
||||||
|
}
|
||||||
|
|
||||||
static int push(lua_State* L, const std::function<Signature>& fx) {
|
static int push(lua_State* L, const std::function<Signature>& fx) {
|
||||||
if (fx) {
|
if (fx) {
|
||||||
function_detail::select<false>(L, fx);
|
function_detail::select<false>(L, fx);
|
||||||
|
|
|
@ -48,6 +48,7 @@ void takefn(std::function<int()> purr) {
|
||||||
|
|
||||||
TEST_CASE("functions/empty std functions", "std::function is allowed to be empty, so it should be serialized to nil") {
|
TEST_CASE("functions/empty std functions", "std::function is allowed to be empty, so it should be serialized to nil") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base);
|
||||||
std::function<void()> foo = nullptr;
|
std::function<void()> foo = nullptr;
|
||||||
sol::function bar;
|
sol::function bar;
|
||||||
|
|
||||||
|
@ -64,8 +65,14 @@ TEST_CASE("functions/empty std functions", "std::function is allowed to be empty
|
||||||
then
|
then
|
||||||
Foo()
|
Foo()
|
||||||
end
|
end
|
||||||
)SCR");
|
)SCR",
|
||||||
|
sol::script_pass_on_error);
|
||||||
REQUIRE_FALSE(result.has_value());
|
REQUIRE_FALSE(result.has_value());
|
||||||
|
|
||||||
|
sol::optional<sol::error> result0 = lua.safe_script(R"SCR(Foo())SCR", sol::script_pass_on_error);
|
||||||
|
REQUIRE(result0.has_value());
|
||||||
|
sol::optional<sol::error> result1 = lua.safe_script(R"SCR(Bar())SCR", sol::script_pass_on_error);
|
||||||
|
REQUIRE(result1.has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("functions/sol::function to std::function", "check if conversion to std::function works properly and calls with correct arguments") {
|
TEST_CASE("functions/sol::function to std::function", "check if conversion to std::function works properly and calls with correct arguments") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user