mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
MSVC needs explicit overloads and explicit =default operators on sol::function
. It's quite whacky, really. Anyway, it compiles, so let's just make sure this works for GCC too.
This commit is contained in:
parent
8db67834b2
commit
2192e98eec
|
@ -58,6 +58,8 @@ public:
|
||||||
function(lua_State* L, int index = -1): reference(L, index) {
|
function(lua_State* L, int index = -1): reference(L, index) {
|
||||||
type_assert(L, index, type::function);
|
type_assert(L, index, type::function);
|
||||||
}
|
}
|
||||||
|
function(const function&) = default;
|
||||||
|
function& operator=(const function&) = default;
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
auto call(Args&&... args) -> decltype(invoke(types<Ret...>(), sizeof...(Args))) {
|
auto call(Args&&... args) -> decltype(invoke(types<Ret...>(), sizeof...(Args))) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "stack.hpp"
|
#include "stack.hpp"
|
||||||
#include "lua_function.hpp"
|
#include "lua_function.hpp"
|
||||||
|
#include "function.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
@ -90,6 +91,37 @@ public:
|
||||||
push();
|
push();
|
||||||
return lua_rawlen(state(), -1);
|
return lua_rawlen(state(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct proxy {
|
||||||
|
private:
|
||||||
|
table& t;
|
||||||
|
T& key;
|
||||||
|
public:
|
||||||
|
proxy(table& t, T& key) : t(t), key(key) {}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
void operator=(U&& other) {
|
||||||
|
typedef Function<Unqualified<U>> isfunction;
|
||||||
|
assign(std::forward<U>(other), isfunction());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
operator U() const {
|
||||||
|
return t.get<U>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename U>
|
||||||
|
void assign(U&& other, std::true_type) {
|
||||||
|
t.set_function(key, std::forward<U>(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
void assign(U&& other, std::false_type) {
|
||||||
|
t.set(key, std::forward<U>(other));
|
||||||
|
}
|
||||||
|
};
|
||||||
private:
|
private:
|
||||||
template<typename T, typename TFx>
|
template<typename T, typename TFx>
|
||||||
table& set_isfunction_fx(std::true_type, T&& key, TFx&& fx) {
|
table& set_isfunction_fx(std::true_type, T&& key, TFx&& fx) {
|
||||||
|
@ -207,30 +239,6 @@ private:
|
||||||
lua_pop(state(), 1);
|
lua_pop(state(), 1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct proxy {
|
|
||||||
private:
|
|
||||||
table& t;
|
|
||||||
T& key;
|
|
||||||
public:
|
|
||||||
proxy(table& t, T& key): t(t), key(key) {}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
DisableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
|
||||||
t.set(key, std::forward<U>(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
EnableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
|
||||||
t.set_function(key, std::forward<U>(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
operator U() const {
|
|
||||||
return t.get<U>(key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
} // sol
|
} // sol
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,11 @@ using Decay = typename std::decay<T>::type;
|
||||||
namespace detail {
|
namespace detail {
|
||||||
// code borrowed from Gears
|
// code borrowed from Gears
|
||||||
// https://github.com/Rapptz/Gears/
|
// https://github.com/Rapptz/Gears/
|
||||||
template<typename T, typename = void>
|
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_function_impl<T, EnableIf<std::is_class<Unqualified<T>>>> {
|
struct is_function_impl<T, true> {
|
||||||
using yes = char;
|
using yes = char;
|
||||||
using no = struct { char s[2]; };
|
using no = struct { char s[2]; };
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ TEST_CASE("tables/functions_variables", "Check if tables and function calls work
|
||||||
std::cout << "stateless lambda()" << std::endl;
|
std::cout << "stateless lambda()" << std::endl;
|
||||||
return "test";
|
return "test";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
REQUIRE_NOTHROW(run_script(lua));
|
REQUIRE_NOTHROW(run_script(lua));
|
||||||
|
|
||||||
lua.get<sol::table>("os").set_function("fun", &free_function);
|
lua.get<sol::table>("os").set_function("fun", &free_function);
|
||||||
|
@ -183,7 +183,7 @@ TEST_CASE("tables/functions_variables", "Check if tables and function calls work
|
||||||
std::cout << "stateless lambda()" << std::endl;
|
std::cout << "stateless lambda()" << std::endl;
|
||||||
return "test";
|
return "test";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
REQUIRE_NOTHROW(run_script(lua));
|
REQUIRE_NOTHROW(run_script(lua));
|
||||||
|
|
||||||
// r-value, cannot optomize
|
// r-value, cannot optomize
|
||||||
|
|
Loading…
Reference in New Issue
Block a user