From 6b54f99e50a31f1e218f0a64a8b0008f645a7d4c Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 25 Apr 2014 20:42:38 -0400 Subject: [PATCH] Do some renaming of lua_function.hpp and fix some compiler errors --- sol/lua_function.hpp | 89 ++++++++++++++++++++++---------------------- sol/userdata.hpp | 4 +- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/sol/lua_function.hpp b/sol/lua_function.hpp index a469348a..06e3979a 100644 --- a/sol/lua_function.hpp +++ b/sol/lua_function.hpp @@ -27,24 +27,24 @@ namespace sol { -template +template struct static_lua_func { - typedef typename std::remove_pointer::type>::type fx_t; - typedef function_traits fx_traits; + typedef typename std::remove_pointer::type>::type function_type; + typedef function_traits traits_type; template - static int typed_call(types, types t, fx_t* fx, lua_State* L) { + static int typed_call(types, types t, function_type* fx, lua_State* L) { stack::pop_call(L, fx, t); return 0; } template - static int typed_call(types<>, types t, fx_t* fx, lua_State* L) { + static int typed_call(types<>, types t, function_type* fx, lua_State* L) { return typed_call(types(), t, fx, L); } template - static int typed_call(types, types t, fx_t* fx, lua_State* L) { + static int typed_call(types, types t, function_type* fx, lua_State* L) { typedef typename multi_return::type return_type; return_type r = stack::pop_call(L, fx, t); stack::push(L, std::move(r)); @@ -52,9 +52,9 @@ struct static_lua_func { } static int call(lua_State* L) { - auto udata = stack::get_user(L); - fx_t* fx = udata.first; - int r = typed_call(tuple_types(), typename fx_traits::args_type(), fx, L); + auto udata = stack::get_user(L); + function_type* fx = udata.first; + int r = typed_call(tuple_types(), typename traits_type::args_type(), fx, L); return r; } @@ -63,25 +63,25 @@ struct static_lua_func { } }; -template +template struct static_object_lua_func { - typedef typename std::remove_pointer::type>::type fx_t; - typedef function_traits fx_traits; + typedef typename std::remove_pointer::type>::type function_type; + typedef function_traits traits_type; template - static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { + static int typed_call(types, types, T& item, function_type& ifx, lua_State* L) { auto fx = [&item, &ifx](Args&&... args) -> void { (item.*ifx)(std::forward(args)...); }; stack::pop_call(L, fx, types()); return 0; } template - static int typed_call(types<>, types t, T& item, fx_t& ifx, lua_State* L) { + static int typed_call(types<>, types t, T& item, function_type& ifx, lua_State* L) { return typed_call(types(), t, item, ifx, L); } template - static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { + static int typed_call(types, types, T& item, function_type& ifx, lua_State* L) { typedef typename multi_return::type return_type; auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward(args)...); }; return_type r = stack::pop_call(L, fx, types()); @@ -90,11 +90,11 @@ struct static_object_lua_func { } static int call(lua_State* L) { - auto memberdata = stack::get_user(L, 1); - auto objdata = stack::get_user(L, memberdata.second); - fx_t& memfx = memberdata.first; - T& obj = *objdata.first; - int r = typed_call(tuple_types(), typename fx_traits::args_type(), obj, memfx, L); + auto memberdata = stack::get_user(L, 1); + auto objdata = stack::get_user(L, memberdata.second); + function_type& memfx = memberdata.first; + T& obj = *objdata.first; + int r = typed_call(tuple_types(), typename traits_type::args_type(), obj, memfx, L); return r; } @@ -107,8 +107,9 @@ struct lua_func { static int call(lua_State* L) { void** pinheritancedata = static_cast(stack::get(L, 1).value); void* inheritancedata = *pinheritancedata; - if (inheritancedata == nullptr) + if (inheritancedata == nullptr) { throw sol_error("call from Lua to C++ function has null data"); + } lua_func* pfx = static_cast(inheritancedata); lua_func& fx = *pfx; int r = fx(L); @@ -131,11 +132,11 @@ struct lua_func { virtual ~lua_func() {} }; -template +template struct functor_lua_func : public lua_func { - typedef decltype(&TFx::operator()) fx_t; - typedef function_traits fx_traits; - TFx fx; + typedef decltype(&Function::operator()) function_type; + typedef function_traits traits_type; + Function fx; template functor_lua_func(FxArgs&&... fxargs): fx(std::forward(fxargs)...) {} @@ -160,15 +161,15 @@ struct functor_lua_func : public lua_func { } virtual int operator()(lua_State* L) override { - return (*this)(tuple_types(), typename fx_traits::args_type(), L); + return (*this)(tuple_types(), typename traits_type::args_type(), L); } }; -template::value> +template::value> struct function_lua_func : public lua_func { - typedef typename std::remove_pointer::type>::type fx_t; - typedef function_traits fx_traits; - fx_t fx; + typedef typename std::remove_pointer::type>::type function_type; + typedef function_traits traits_type; + function_type fx; template function_lua_func(FxArgs&&... fxargs): fx(std::forward(fxargs)...) {} @@ -193,23 +194,23 @@ struct function_lua_func : public lua_func { } virtual int operator()(lua_State* L) override { - return (*this)(tuple_types(), typename fx_traits::args_type(), L); + return (*this)(tuple_types(), typename traits_type::args_type(), L); } }; -template -struct function_lua_func : public lua_func { - typedef typename std::remove_pointer::type>::type fx_t; - typedef function_traits fx_traits; +template +struct function_lua_func : public lua_func { + typedef typename std::remove_pointer::type>::type function_type; + typedef function_traits traits_type; struct functor { T member; - fx_t invocation; + function_type invocation; template functor(T m, FxArgs&&... fxargs): member(std::move(m)), invocation(std::forward(fxargs)...) {} template - typename fx_traits::return_type operator()(Args&&... args) { + typename traits_type::return_type operator()(Args&&... args) { return (member.*invocation)(std::forward(args)...); } } fx; @@ -237,17 +238,17 @@ struct function_lua_func : public lua_func { } virtual int operator()(lua_State* L) override { - return (*this)(tuple_types(), typename fx_traits::args_type(), L); + return (*this)(tuple_types(), typename traits_type::args_type(), L); } }; -template +template struct class_lua_func : public lua_func { - typedef typename std::remove_pointer::type>::type fx_t; - typedef function_traits fx_traits; + typedef typename std::remove_pointer::type>::type function_type; + typedef function_traits traits_type; struct functor { T* item; - fx_t invocation; + function_type invocation; template functor(FxArgs&&... fxargs): item(nullptr), invocation(std::forward(fxargs)...) {} @@ -258,7 +259,7 @@ struct class_lua_func : public lua_func { } template - typename fx_traits::return_type operator()(Args&&... args) { + typename traits_type::return_type operator()(Args&&... args) { T& member = *item; return (member.*invocation)(std::forward(args)...); } @@ -288,7 +289,7 @@ struct class_lua_func : public lua_func { virtual int operator()(lua_State* L) override { fx.pre_call(L); - return (*this)(tuple_types(), typename fx_traits::args_type(), L); + return (*this)(tuple_types(), typename traits_type::args_type(), L); } }; diff --git a/sol/userdata.hpp b/sol/userdata.hpp index 817dc521..4c53d2a8 100644 --- a/sol/userdata.hpp +++ b/sol/userdata.hpp @@ -130,7 +130,7 @@ public: } template - userdata(std::string name, constructors c, Args&&... args) : luaname(std::move(name)) { + userdata(std::string name, constructors, Args&&... args) : luaname(std::move(name)) { functionnames.reserve(sizeof...(args)); functiontable.reserve(sizeof...(args)); functions.reserve(sizeof...(args)); @@ -158,4 +158,4 @@ const std::string userdata::meta = std::string("sol.stateful.").append(classn } -#endif SOL_USERDATA_HPP +#endif // SOL_USERDATA_HPP