mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
static members are hard to deal with in regular memory...
Also, make sure tuple returns don't get shafted by the tuple_types machinery!
This commit is contained in:
parent
4b545aa6a2
commit
3e17b24065
|
@ -108,7 +108,10 @@ public:
|
||||||
|
|
||||||
class function : public reference {
|
class function : public reference {
|
||||||
public:
|
public:
|
||||||
static reference default_handler;
|
static reference& default_handler() {
|
||||||
|
static sol::reference h;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct handler {
|
struct handler {
|
||||||
|
@ -196,7 +199,7 @@ public:
|
||||||
sol::reference error_handler;
|
sol::reference error_handler;
|
||||||
|
|
||||||
function() = default;
|
function() = default;
|
||||||
function(lua_State* L, int index = -1): reference(L, index), error_handler(default_handler) {
|
function(lua_State* L, int index = -1): reference(L, index), error_handler(default_handler()) {
|
||||||
type_assert(L, index, type::function);
|
type_assert(L, index, type::function);
|
||||||
}
|
}
|
||||||
function(const function&) = default;
|
function(const function&) = default;
|
||||||
|
@ -226,8 +229,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sol::reference function::default_handler;
|
|
||||||
|
|
||||||
namespace stack {
|
namespace stack {
|
||||||
template<typename... Sigs>
|
template<typename... Sigs>
|
||||||
struct pusher<function_sig_t<Sigs...>> {
|
struct pusher<function_sig_t<Sigs...>> {
|
||||||
|
|
16
tests.cpp
16
tests.cpp
|
@ -472,20 +472,24 @@ TEST_CASE("functions/overloaded", "Check if overloaded function resolution templ
|
||||||
|
|
||||||
TEST_CASE("functions/return_order_and_multi_get", "Check if return order is in the same reading order specified in Lua") {
|
TEST_CASE("functions/return_order_and_multi_get", "Check if return order is in the same reading order specified in Lua") {
|
||||||
const static std::tuple<int, int, int> triple = std::make_tuple(10, 11, 12);
|
const static std::tuple<int, int, int> triple = std::make_tuple(10, 11, 12);
|
||||||
|
const static std::tuple<int, float> paired = std::make_tuple(10, 10.f);
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.set_function("f", [] {
|
lua.set_function("f", [] {
|
||||||
return std::make_tuple(10, 11, 12);
|
return std::make_tuple(10, 11, 12);
|
||||||
});
|
} );
|
||||||
|
int a = 0;
|
||||||
|
lua.set_function( "h", []() {
|
||||||
|
return std::make_tuple( 10, 10.0f );
|
||||||
|
} );
|
||||||
lua.script("function g() return 10, 11, 12 end\nx,y,z = g()");
|
lua.script("function g() return 10, 11, 12 end\nx,y,z = g()");
|
||||||
auto tcpp = lua.get<sol::function>("f").call<int, int, int>();
|
auto tcpp = lua.get<sol::function>("f").call<int, int, int>();
|
||||||
auto tlua = lua.get<sol::function>("g").call<int, int, int>();
|
auto tlua = lua.get<sol::function>( "g" ).call<int, int, int>();
|
||||||
auto tluaget = lua.get<int, int, int>("x", "y", "z");
|
auto tcpp2 = lua.get<sol::function>( "h" ).call<int, float>();
|
||||||
std::cout << "cpp: " << std::get<0>(tcpp) << ',' << std::get<1>(tcpp) << ',' << std::get<2>(tcpp) << std::endl;
|
auto tluaget = lua.get<int, int, int>( "x", "y", "z" );
|
||||||
std::cout << "lua: " << std::get<0>(tlua) << ',' << std::get<1>(tlua) << ',' << std::get<2>(tlua) << std::endl;
|
|
||||||
std::cout << "lua xyz: " << lua.get<int>("x") << ',' << lua.get<int>("y") << ',' << lua.get<int>("z") << std::endl;
|
|
||||||
REQUIRE(tcpp == triple);
|
REQUIRE(tcpp == triple);
|
||||||
REQUIRE(tlua == triple);
|
REQUIRE(tlua == triple);
|
||||||
REQUIRE(tluaget == triple);
|
REQUIRE(tluaget == triple);
|
||||||
|
REQUIRE(tcpp2 == paired);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("functions/deducing_return_order_and_multi_get", "Check if return order is in the same reading order specified in Lua, with regular deducing calls") {
|
TEST_CASE("functions/deducing_return_order_and_multi_get", "Check if return order is in the same reading order specified in Lua, with regular deducing calls") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user