mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix compiler errors, tests failing however
This commit is contained in:
parent
a525760178
commit
63bc2b06cb
@ -31,7 +31,7 @@ template<typename Function>
|
|||||||
struct static_function {
|
struct static_function {
|
||||||
typedef typename std::remove_pointer<typename std::decay<Function>::type>::type function_type;
|
typedef typename std::remove_pointer<typename std::decay<Function>::type>::type function_type;
|
||||||
typedef function_traits<function_type> traits_type;
|
typedef function_traits<function_type> traits_type;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
static int typed_call(types<void>, types<Args...> t, function_type* fx, lua_State* L) {
|
static int typed_call(types<void>, types<Args...> t, function_type* fx, lua_State* L) {
|
||||||
stack::pop_call(L, fx, t);
|
stack::pop_call(L, fx, t);
|
||||||
@ -105,17 +105,21 @@ struct static_member_function {
|
|||||||
|
|
||||||
struct base_function {
|
struct base_function {
|
||||||
static int base_call(lua_State* L, void* inheritancedata) {
|
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");
|
throw sol_error("call from Lua to C++ function has null data");
|
||||||
|
}
|
||||||
|
|
||||||
base_function* pfx = static_cast<base_function*>(inheritancedata);
|
base_function* pfx = static_cast<base_function*>(inheritancedata);
|
||||||
base_function& fx = *pfx;
|
base_function& fx = *pfx;
|
||||||
int r = fx(L);
|
int r = fx(L);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int base_gc(lua_State* L, void* udata) {
|
static int base_gc(lua_State*, void* udata) {
|
||||||
if (udata == nullptr)
|
if (udata == nullptr) {
|
||||||
throw sol_error("call from lua to C++ gc function with null data");
|
throw sol_error("call from lua to C++ gc function with null data");
|
||||||
|
}
|
||||||
|
|
||||||
base_function* ptr = static_cast<base_function*>(udata);
|
base_function* ptr = static_cast<base_function*>(udata);
|
||||||
std::default_delete<base_function> dx{};
|
std::default_delete<base_function> dx{};
|
||||||
dx(ptr);
|
dx(ptr);
|
||||||
@ -139,7 +143,7 @@ struct base_function {
|
|||||||
return base_call(L, stack::get<lightuserdata_t>(L, i + 1));
|
return base_call(L, stack::get<lightuserdata_t>(L, i + 1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual int operator()(lua_State*) {
|
virtual int operator()(lua_State*) {
|
||||||
throw sol_error("failure to call specialized wrapped C++ function from Lua");
|
throw sol_error("failure to call specialized wrapped C++ function from Lua");
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ inline void push_tuple(lua_State* L, indices<I...>, T&& tuplen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename... Vs, typename... Args>
|
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)...);
|
return f(std::forward<Vs>(vs)...);
|
||||||
}
|
}
|
||||||
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>
|
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>
|
||||||
|
@ -46,22 +46,22 @@ private:
|
|||||||
std::vector<std::string> functionnames;
|
std::vector<std::string> functionnames;
|
||||||
std::vector<std::unique_ptr<base_function>> functions;
|
std::vector<std::unique_ptr<base_function>> functions;
|
||||||
std::vector<luaL_Reg> functiontable;
|
std::vector<luaL_Reg> functiontable;
|
||||||
|
|
||||||
template<typename... TTypes>
|
template<typename... TTypes>
|
||||||
struct constructor {
|
struct constructor {
|
||||||
template<typename... Args>
|
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 {
|
auto fx = [&obj] (Args&&... args) -> void {
|
||||||
std::allocator<T> alloc{};
|
std::allocator<T> alloc{};
|
||||||
alloc.construct(obj, std::forward<Args>(args)...);
|
alloc.construct(obj, std::forward<Args>(args)...);
|
||||||
};
|
};
|
||||||
stack::get_call(L, 1 + static_cast<int>(syntax), fx, types<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");
|
throw sol_error("No matching constructor for the arguments provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ...CArgs, typename... Args>
|
template<typename ...CArgs, typename... Args>
|
||||||
static void match_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types<CArgs...> t, Args&&... args) {
|
static void match_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types<CArgs...> t, Args&&... args) {
|
||||||
if (argcount == sizeof...(CArgs)) {
|
if (argcount == sizeof...(CArgs)) {
|
||||||
@ -74,16 +74,14 @@ private:
|
|||||||
static int construct(lua_State* L) {
|
static int construct(lua_State* L) {
|
||||||
call_syntax syntax = stack::get_call_syntax(L, meta);
|
call_syntax syntax = stack::get_call_syntax(L, meta);
|
||||||
int argcount = lua_gettop(L);
|
int argcount = lua_gettop(L);
|
||||||
|
|
||||||
void* udata = lua_newuserdata(L, sizeof(T));
|
void* udata = lua_newuserdata(L, sizeof(T));
|
||||||
T* obj = static_cast<T*>(udata);
|
T* obj = static_cast<T*>(udata);
|
||||||
match_constructor(L, obj, syntax,
|
match_constructor(L, obj, syntax, argcount - static_cast<int>(syntax), typename std::common_type<TTypes>::type()...);
|
||||||
argcount - static_cast<int>(syntax),
|
|
||||||
std::common_type<TTypes>::type()...);
|
|
||||||
|
|
||||||
luaL_getmetatable(L, meta.c_str());
|
luaL_getmetatable(L, meta.c_str());
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -91,9 +89,6 @@ private:
|
|||||||
template<std::size_t n>
|
template<std::size_t n>
|
||||||
struct destructor {
|
struct destructor {
|
||||||
static int destruct(lua_State* L) {
|
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);
|
userdata_t udata = stack::get<userdata_t>(L, 1);
|
||||||
T* obj = static_cast<T*>(udata.value);
|
T* obj = static_cast<T*>(udata.value);
|
||||||
std::allocator<T> alloc{};
|
std::allocator<T> alloc{};
|
||||||
@ -103,9 +98,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<std::size_t n>
|
template<std::size_t n>
|
||||||
void build_function_tables() {
|
void build_function_tables() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t n, typename... Args, typename Ret, typename... MArgs>
|
template<std::size_t n, typename... Args, typename Ret, typename... MArgs>
|
||||||
void build_function_tables(Ret(T::* func)(MArgs...), std::string name, Args&&... args) {
|
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 });
|
functiontable.push_back({ functionnames.back().c_str(), &constructor<CArgs...>::construct });
|
||||||
functionnames.push_back("__gc");
|
functionnames.push_back("__gc");
|
||||||
functiontable.push_back({ functionnames.back().c_str(), &destructor<sizeof...(Args) / 2>::destruct });
|
functiontable.push_back({ functionnames.back().c_str(), &destructor<sizeof...(Args) / 2>::destruct });
|
||||||
|
|
||||||
functiontable.push_back({ nullptr, nullptr });
|
functiontable.push_back({ nullptr, nullptr });
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_into(const table& s) { }
|
void register_into(const table& s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user