Fix compiler errors, tests failing however

This commit is contained in:
Rapptz 2014-04-27 00:53:57 -04:00
parent a525760178
commit 63bc2b06cb
3 changed files with 22 additions and 25 deletions

View File

@ -31,7 +31,7 @@ template<typename Function>
struct static_function {
typedef typename std::remove_pointer<typename std::decay<Function>::type>::type function_type;
typedef function_traits<function_type> traits_type;
template<typename... Args>
static int typed_call(types<void>, types<Args...> t, function_type* fx, lua_State* L) {
stack::pop_call(L, fx, t);
@ -105,17 +105,21 @@ struct static_member_function {
struct base_function {
static int base_call(lua_State* L, void* inheritancedata) {
if (inheritancedata == nullptr)
if (inheritancedata == nullptr) {
throw sol_error("call from Lua to C++ function has null data");
}
base_function* pfx = static_cast<base_function*>(inheritancedata);
base_function& fx = *pfx;
int r = fx(L);
return r;
}
static int base_gc(lua_State* L, void* udata) {
if (udata == nullptr)
static int base_gc(lua_State*, void* udata) {
if (udata == nullptr) {
throw sol_error("call from lua to C++ gc function with null data");
}
base_function* ptr = static_cast<base_function*>(udata);
std::default_delete<base_function> dx{};
dx(ptr);
@ -139,7 +143,7 @@ struct base_function {
return base_call(L, stack::get<lightuserdata_t>(L, i + 1));
}
};
virtual int operator()(lua_State*) {
throw sol_error("failure to call specialized wrapped C++ function from Lua");
}

View File

@ -240,7 +240,7 @@ inline void push_tuple(lua_State* L, indices<I...>, T&& tuplen) {
}
template<typename F, typename... Vs, typename... Args>
inline auto ltr_get(lua_State*, int index, F&& f, types<Args...>, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
inline auto ltr_get(lua_State*, int, F&& f, types<Args...>, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
return f(std::forward<Vs>(vs)...);
}
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>

View File

@ -46,22 +46,22 @@ private:
std::vector<std::string> functionnames;
std::vector<std::unique_ptr<base_function>> functions;
std::vector<luaL_Reg> functiontable;
template<typename... TTypes>
struct constructor {
template<typename... Args>
static void do_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types<Args...>) {
static void do_constructor(lua_State* L, T* obj, call_syntax syntax, int, types<Args...>) {
auto fx = [&obj] (Args&&... args) -> void {
std::allocator<T> alloc{};
std::allocator<T> alloc{};
alloc.construct(obj, std::forward<Args>(args)...);
};
stack::get_call(L, 1 + static_cast<int>(syntax), fx, types<Args...>());
}
static void match_constructor(lua_State* L, T* obj, call_syntax, int argcount) {
static void match_constructor(lua_State*, T*, call_syntax, int) {
throw sol_error("No matching constructor for the arguments provided");
}
template<typename ...CArgs, typename... Args>
static void match_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types<CArgs...> t, Args&&... args) {
if (argcount == sizeof...(CArgs)) {
@ -74,16 +74,14 @@ private:
static int construct(lua_State* L) {
call_syntax syntax = stack::get_call_syntax(L, meta);
int argcount = lua_gettop(L);
void* udata = lua_newuserdata(L, sizeof(T));
T* obj = static_cast<T*>(udata);
match_constructor(L, obj, syntax,
argcount - static_cast<int>(syntax),
std::common_type<TTypes>::type()...);
match_constructor(L, obj, syntax, argcount - static_cast<int>(syntax), typename std::common_type<TTypes>::type()...);
luaL_getmetatable(L, meta.c_str());
lua_setmetatable(L, -2);
return 1;
}
};
@ -91,9 +89,6 @@ private:
template<std::size_t n>
struct destructor {
static int destruct(lua_State* L) {
/*for(std::size_t i = 0; i < n; ++i) {
base_function::base_gc(L, stack::get<lightuserdata_t>(L, i + 1));
}*/
userdata_t udata = stack::get<userdata_t>(L, 1);
T* obj = static_cast<T*>(udata.value);
std::allocator<T> alloc{};
@ -103,9 +98,7 @@ private:
};
template<std::size_t n>
void build_function_tables() {
}
void build_function_tables() {}
template<std::size_t n, typename... Args, typename Ret, typename... MArgs>
void build_function_tables(Ret(T::* func)(MArgs...), std::string name, Args&&... args) {
@ -134,11 +127,11 @@ public:
functiontable.push_back({ functionnames.back().c_str(), &constructor<CArgs...>::construct });
functionnames.push_back("__gc");
functiontable.push_back({ functionnames.back().c_str(), &destructor<sizeof...(Args) / 2>::destruct });
functiontable.push_back({ nullptr, nullptr });
}
void register_into(const table& s) { }
void register_into(const table& s) {}
};
template<typename T>