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:
ThePhD 2013-12-13 14:16:59 -05:00
parent 8db67834b2
commit 2192e98eec
4 changed files with 38 additions and 28 deletions

View File

@ -58,6 +58,8 @@ public:
function(lua_State* L, int index = -1): reference(L, index) {
type_assert(L, index, type::function);
}
function(const function&) = default;
function& operator=(const function&) = default;
template<typename... Ret, typename... Args>
auto call(Args&&... args) -> decltype(invoke(types<Ret...>(), sizeof...(Args))) {

View File

@ -24,6 +24,7 @@
#include "stack.hpp"
#include "lua_function.hpp"
#include "function.hpp"
#include <array>
#include <cstring>
@ -90,6 +91,37 @@ public:
push();
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:
template<typename T, typename TFx>
table& set_isfunction_fx(std::true_type, T&& key, TFx&& fx) {
@ -207,30 +239,6 @@ private:
lua_pop(state(), 1);
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

View File

@ -40,11 +40,11 @@ using Decay = typename std::decay<T>::type;
namespace detail {
// code borrowed from 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> {};
template<typename T>
struct is_function_impl<T, EnableIf<std::is_class<Unqualified<T>>>> {
struct is_function_impl<T, true> {
using yes = char;
using no = struct { char s[2]; };

View File

@ -165,7 +165,7 @@ TEST_CASE("tables/functions_variables", "Check if tables and function calls work
std::cout << "stateless lambda()" << std::endl;
return "test";
}
);
);
REQUIRE_NOTHROW(run_script(lua));
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;
return "test";
}
);
);
REQUIRE_NOTHROW(run_script(lua));
// r-value, cannot optomize