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 {
|
||||
public:
|
||||
static reference default_handler;
|
||||
static reference& default_handler() {
|
||||
static sol::reference h;
|
||||
return h;
|
||||
}
|
||||
|
||||
private:
|
||||
struct handler {
|
||||
|
@ -196,7 +199,7 @@ public:
|
|||
sol::reference error_handler;
|
||||
|
||||
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);
|
||||
}
|
||||
function(const function&) = default;
|
||||
|
@ -226,8 +229,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
sol::reference function::default_handler;
|
||||
|
||||
namespace stack {
|
||||
template<typename... Sigs>
|
||||
struct pusher<function_sig_t<Sigs...>> {
|
||||
|
|
10
tests.cpp
10
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") {
|
||||
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;
|
||||
lua.set_function("f", [] {
|
||||
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()");
|
||||
auto tcpp = lua.get<sol::function>("f").call<int, int, int>();
|
||||
auto tlua = lua.get<sol::function>( "g" ).call<int, int, int>();
|
||||
auto tcpp2 = lua.get<sol::function>( "h" ).call<int, float>();
|
||||
auto tluaget = lua.get<int, int, int>( "x", "y", "z" );
|
||||
std::cout << "cpp: " << std::get<0>(tcpp) << ',' << std::get<1>(tcpp) << ',' << std::get<2>(tcpp) << std::endl;
|
||||
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(tlua == 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") {
|
||||
|
|
Loading…
Reference in New Issue
Block a user