diff --git a/sol/function_types.hpp b/sol/function_types.hpp index 16f3f957..046956ec 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -31,7 +31,7 @@ template struct static_function { typedef typename std::remove_pointer::type>::type function_type; typedef function_traits traits_type; - + template static int typed_call(types, types 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(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(udata); std::default_delete dx{}; dx(ptr); @@ -139,7 +143,7 @@ struct base_function { return base_call(L, stack::get(L, i + 1)); } }; - + virtual int operator()(lua_State*) { throw sol_error("failure to call specialized wrapped C++ function from Lua"); } diff --git a/sol/stack.hpp b/sol/stack.hpp index 94f40194..8f93c2a3 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -240,7 +240,7 @@ inline void push_tuple(lua_State* L, indices, T&& tuplen) { } template -inline auto ltr_get(lua_State*, int index, F&& f, types, types<>, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { +inline auto ltr_get(lua_State*, int, F&& f, types, types<>, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { return f(std::forward(vs)...); } template diff --git a/sol/userdata.hpp b/sol/userdata.hpp index 78388e42..3f5edce3 100644 --- a/sol/userdata.hpp +++ b/sol/userdata.hpp @@ -46,22 +46,22 @@ private: std::vector functionnames; std::vector> functions; std::vector functiontable; - + template struct constructor { template - static void do_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types) { + static void do_constructor(lua_State* L, T* obj, call_syntax syntax, int, types) { auto fx = [&obj] (Args&&... args) -> void { - std::allocator alloc{}; + std::allocator alloc{}; alloc.construct(obj, std::forward(args)...); }; stack::get_call(L, 1 + static_cast(syntax), fx, types()); } - 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 static void match_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types 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(udata); - match_constructor(L, obj, syntax, - argcount - static_cast(syntax), - std::common_type::type()...); - + match_constructor(L, obj, syntax, argcount - static_cast(syntax), typename std::common_type::type()...); + luaL_getmetatable(L, meta.c_str()); lua_setmetatable(L, -2); - + return 1; } }; @@ -91,9 +89,6 @@ private: template struct destructor { static int destruct(lua_State* L) { - /*for(std::size_t i = 0; i < n; ++i) { - base_function::base_gc(L, stack::get(L, i + 1)); - }*/ userdata_t udata = stack::get(L, 1); T* obj = static_cast(udata.value); std::allocator alloc{}; @@ -103,9 +98,7 @@ private: }; template - void build_function_tables() { - - } + void build_function_tables() {} template 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::construct }); functionnames.push_back("__gc"); functiontable.push_back({ functionnames.back().c_str(), &destructor::destruct }); - + functiontable.push_back({ nullptr, nullptr }); } - void register_into(const table& s) { } + void register_into(const table& s) {} }; template