From da76793c307b335c25f8a5b67bc93e52ec24c289 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 10 Aug 2014 20:49:34 -0400 Subject: [PATCH] Formatting changes. --- sol/debug.hpp | 11 +++---- sol/default_construct.hpp | 2 -- sol/function.hpp | 10 +++--- sol/function_types.hpp | 49 +++++++++++++++-------------- sol/proxy.hpp | 2 +- sol/resolve.hpp | 66 +++++++++++++++++++-------------------- sol/stack.hpp | 11 ++++--- sol/state.hpp | 2 +- sol/traits.hpp | 6 ++-- sol/types.hpp | 12 +++---- sol/userdata.hpp | 65 +++++++++++++++++++------------------- 11 files changed, 118 insertions(+), 118 deletions(-) diff --git a/sol/debug.hpp b/sol/debug.hpp index 600b8989..4fe2c7b8 100644 --- a/sol/debug.hpp +++ b/sol/debug.hpp @@ -27,26 +27,25 @@ namespace sol { namespace debug { - inline std::string dump_types(lua_State* L) { std::string visual; std::size_t size = lua_gettop(L) + 1; - for (std::size_t i = 1; i < size; ++i) { - if (i != 1) + for(std::size_t i = 1; i < size; ++i) { + if(i != 1) { visual += " | "; + } visual += type_name(L, stack::get(L, i)); } return visual; } -inline void print_stack (lua_State* L) { +inline void print_stack(lua_State* L) { std::cout << dump_types(L) << std::endl; } -inline void print_section (const std::string& message, lua_State* L) { +inline void print_section(const std::string& message, lua_State* L) { std::cout << "-- " << message << " -- [ " << dump_types(L) << " ]" << std::endl; } - } // debug } // sol diff --git a/sol/default_construct.hpp b/sol/default_construct.hpp index 4f8c8f1e..90ad3264 100644 --- a/sol/default_construct.hpp +++ b/sol/default_construct.hpp @@ -26,7 +26,6 @@ #include "traits.hpp" namespace sol { - struct default_construct { template void operator()(T&& obj, Args&&... args) const { @@ -34,7 +33,6 @@ struct default_construct { alloc.construct(obj, std::forward(args)...); } }; - } // sol #endif // SOL_DEFAULT_CONSTRUCTOR_HPP diff --git a/sol/function.hpp b/sol/function.hpp index 0c1fb191..d349f9c9 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -35,7 +35,7 @@ namespace sol { class function : public reference { private: - void luacall (std::size_t argcount, std::size_t resultcount) const { + void luacall(std::size_t argcount, std::size_t resultcount) const { lua_call(state(), static_cast(argcount), static_cast(resultcount)); } @@ -60,7 +60,7 @@ private: } public: - function() : reference() {} + function() = default; function(lua_State* L, int index = -1): reference(L, index) { type_assert(L, index, type::function); } @@ -197,7 +197,7 @@ struct pusher> { void* userdata = reinterpret_cast(target); lua_CFunction freefunc = &base_function::call; - if (luaL_newmetatable(L, metatablename) == 1) { + if(luaL_newmetatable(L, metatablename) == 1) { lua_pushstring(L, "__gc"); stack::push(L, &base_function::gc); lua_settable(L, -3); @@ -231,7 +231,7 @@ struct getter> { static std::function get_std_func(types, types, lua_State* L, int index = -1) { typedef typename function_traits::return_type return_t; sol::function f(L, index); - auto fx = [ f, L, index ] (FxArgs&&... args) -> return_t { + auto fx = [f, L, index](FxArgs&&... args) -> return_t { return f(types(), std::forward(args)...); }; return std::move(fx); @@ -240,7 +240,7 @@ struct getter> { template static std::function get_std_func(types, types, lua_State* L, int index = -1) { sol::function f(L, index); - auto fx = [ f, L, index ] (FxArgs&&... args) -> void { + auto fx = [f, L, index](FxArgs&&... args) -> void { f(std::forward(args)...); }; return std::move(fx); diff --git a/sol/function_types.hpp b/sol/function_types.hpp index 6f363988..26c88d38 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -202,7 +202,7 @@ struct static_member_function { struct base_function { static int base_call(lua_State* L, void* inheritancedata) { - if (inheritancedata == nullptr) { + if(inheritancedata == nullptr) { throw error("call from Lua to C++ function has null data"); } @@ -213,7 +213,7 @@ struct base_function { } static int ref_base_call(lua_State* L, void* inheritancedata) { - if (inheritancedata == nullptr) { + if(inheritancedata == nullptr) { throw error("call from Lua to C++ function has null data"); } @@ -224,7 +224,7 @@ struct base_function { } static int base_gc(lua_State*, void* udata) { - if (udata == nullptr) { + if(udata == nullptr) { throw error("call from lua to C++ gc function with null data"); } @@ -256,7 +256,7 @@ struct base_function { } static int gc(lua_State* L) { - for (std::size_t i = 0; i < I; ++i) { + for(std::size_t i = 0; i < I; ++i) { upvalue_t up = stack::get(L, i + 1); base_function* obj = static_cast(up.value); std::allocator alloc{}; @@ -385,7 +385,7 @@ struct userdata_function_core : public base_function { template> typename std::enable_if::value, void>::type push(lua_State* L, Return&& r) { - if (detail::get_ptr(r) == fx.item) { + if(detail::get_ptr(r) == fx.item) { // push nothing // note that pushing nothing with the ':' // syntax means we leave the instance of what @@ -442,8 +442,9 @@ struct userdata_function : public userdata_function_core { template int fx_call(lua_State* L) { this->fx.item = detail::get_ptr(stack::get(L, 1)); - if (this->fx.item == nullptr) + if(this->fx.item == nullptr) { throw error("userdata for function call is null: are you using the wrong syntax? (use item:function/variable(...) syntax)"); + } return static_cast(*this)(tuple_types(), args_type(), L); } @@ -468,12 +469,14 @@ struct userdata_variable_function : public userdata_function_core userdata_variable_function(FxArgs&&... fxargs): base_t(std::forward(fxargs)...) {} template - int fx_call (lua_State* L) { + int fx_call(lua_State* L) { this->fx.item = detail::get_ptr(stack::get(L, 1)); - if (this->fx.item == nullptr) + if(this->fx.item == nullptr) { throw error("userdata for member variable is null"); + } + int argcount = lua_gettop(L); - switch (argcount) { + switch(argcount) { case 2: return static_cast(*this)(tuple_types(), types<>(), L); case 3: @@ -508,31 +511,29 @@ struct userdata_indexing_function : public userdata_function_core userdata_indexing_function(std::string name, FxArgs&&... fxargs): base_t(std::forward(fxargs)...), name(std::move(name)) {} template - int fx_call (lua_State* L) { + int fx_call(lua_State* L) { std::string accessor = stack::get(L, 1 - lua_gettop(L)); auto function = functions.find(accessor); - if (function != functions.end()) { - if (function->second.second) { + if(function != functions.end()) { + if(function->second.second) { stack::push(L, function->second.first.get()); - if (std::is_same::value) + if(std::is_same::value) { stack::push(L, &base_function::userdata<0>::ref_call, 1); - else + } + else { stack::push(L, &base_function::userdata<0>::call, 1); + } return 1; } + else if(std::is_same::value) { + return (*function->second.first)(L, detail::ref_call); + } else { - if (std::is_same::value) - return (*function->second.first)(L, detail::ref_call); - else - return (*function->second.first)(L); + return (*function->second.first)(L); } } - if (this->fx.invocation == nullptr) { - std::string err = "invalid indexing \""; - err += accessor; - err += "\" on type: "; - err += name; - throw error(err); + if(this->fx.invocation == nullptr) { + throw error("invalid indexing \"" + accessor + "\" on type: " + name); } this->fx.item = detail::get_ptr(stack::get(L, 1)); return static_cast(*this)(tuple_types(), args_type(), L); diff --git a/sol/proxy.hpp b/sol/proxy.hpp index be915444..4c46804b 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -65,7 +65,7 @@ public: tbl.set(key, std::forward(other)); } - operator nil_t () const { + operator nil_t() const { return get(); } diff --git a/sol/resolve.hpp b/sol/resolve.hpp index 80c5ae9f..0d849d0b 100644 --- a/sol/resolve.hpp +++ b/sol/resolve.hpp @@ -27,68 +27,68 @@ namespace sol { namespace detail { -template( Args... )>::type> -auto resolve_i( types, F&& )->R( Unqualified::* )( Args... ) { - typedef R( Sig )( Args... ); +template(Args...)>::type> +auto resolve_i(types, F&&)->R(Unqualified::*)(Args...) { + using Sig = R(Args...); typedef Unqualified Fu; - return static_cast( &Fu::operator() ); + return static_cast(&Fu::operator()); } -template -auto resolve_f( std::true_type, F&& f ) -> decltype( resolve_i( types::operator() )>>( ), std::forward( f ) ) ) { - typedef Unqualified Fu; - return resolve_i( types>( ), std::forward( f ) ); +template> +auto resolve_f(std::true_type, F&& f) -> decltype(resolve_i(types>(), std::forward(f))) { + return resolve_i(types>(), std::forward(f)); } -template -void resolve_f( std::false_type, F&& ) { - static_assert( has_deducible_signature::value, "Cannot use no-template-parameter call with an overloaded functor: specify the signature" ); +template +void resolve_f(std::false_type, F&&) { + static_assert(has_deducible_signature::value, + "Cannot use no-template-parameter call with an overloaded functor: specify the signature"); } -template -auto resolve_i( types<>, F&& f ) -> decltype( resolve_f( has_deducible_signature> {}, std::forward( f ) ) ) { - return resolve_f( has_deducible_signature> {}, std::forward( f ) ); +template> +auto resolve_i(types<>, F&& f) -> decltype(resolve_f(has_deducible_signature {}, std::forward(f))) { + return resolve_f(has_deducible_signature {}, std::forward(f)); } -template::type> -auto resolve_i( types, F&& f ) -> decltype( resolve_i( types( ), std::forward( f ) ) ) { - return resolve_i( types( ), std::forward( f ) ); +template::type> +auto resolve_i(types, F&& f) -> decltype( resolve_i(types(), std::forward(f))) { + return resolve_i(types(), std::forward(f)); } -template -Sig C::* resolve_v( std::false_type, Sig C::* mem_func_ptr ) { +template +Sig C::* resolve_v(std::false_type, Sig C::* mem_func_ptr) { return mem_func_ptr; } -template -Sig C::* resolve_v( std::true_type, Sig C::* mem_variable_ptr ) { +template +Sig C::* resolve_v(std::true_type, Sig C::* mem_variable_ptr) { return mem_variable_ptr; } } // detail -template -auto resolve( R fun_ptr( Args... ) ) -> R( *)( Args... ) { +template +auto resolve(R fun_ptr(Args...)) -> R(*)(Args...) { return fun_ptr; } -template -Sig* resolve( Sig* fun_ptr ) { +template +Sig* resolve(Sig* fun_ptr) { return fun_ptr; } -template -auto resolve( R( C::*mem_ptr )( Args... ) ) -> R( C::* )( Args... ) { +template +auto resolve(R(C::*mem_ptr)(Args...)) -> R(C::*)(Args...) { return mem_ptr; } -template -Sig C::* resolve( Sig C::* mem_ptr ) { - return detail::resolve_v( std::is_member_object_pointer( ), mem_ptr ); +template +Sig C::* resolve(Sig C::* mem_ptr) { + return detail::resolve_v(std::is_member_object_pointer(), mem_ptr); } -template -auto resolve( F&& f ) -> decltype( detail::resolve_i( types( ), std::forward( f ) ) ) { - return detail::resolve_i( types( ), std::forward( f ) ); +template +auto resolve(F&& f) -> decltype(detail::resolve_i(types(), std::forward(f))) { + return detail::resolve_i(types(), std::forward(f)); } } // sol diff --git a/sol/stack.hpp b/sol/stack.hpp index 3aff2436..55c1cacc 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -160,8 +160,9 @@ struct getter { template<> struct getter { static nil_t get(lua_State* L, int index = -1) { - if (lua_isnil(L, index) == 0) + if(lua_isnil(L, index) == 0) { throw sol::error("not nil"); + } return nil_t{ }; } }; @@ -377,7 +378,7 @@ inline int push_as_upvalues(lua_State* L, T& item) { data_t data{{}}; std::memcpy(std::addressof(data[0]), std::addressof(item), itemsize); - for (auto&& v : data) { + for(auto&& v : data) { push(L, upvalue_t(v)); } return data_t_count; @@ -388,7 +389,7 @@ inline std::pair get_as_upvalues(lua_State* L, int index = 1) { const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*); typedef std::array data_t; data_t voiddata{ {} }; - for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { + for(std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { voiddata[i] = get(L, index++); } return std::pair(*reinterpret_cast(static_cast(voiddata.data())), index); @@ -475,8 +476,8 @@ inline auto pop_reverse_call(lua_State* L, TFx&& fx, types t) -> declty } inline call_syntax get_call_syntax(lua_State* L, const std::string& meta) { - if (get(L, 1) == type::table) { - if (luaL_newmetatable(L, meta.c_str()) == 0) { + if(get(L, 1) == type::table) { + if(luaL_newmetatable(L, meta.c_str()) == 0) { lua_settop(L, -2); return call_syntax::colon; } diff --git a/sol/state.hpp b/sol/state.hpp index 3b4aa448..b7401888 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -130,7 +130,7 @@ public: } void open_file(const std::string& filename) { - if (luaL_dofile(L.get(), filename.c_str())) { + if(luaL_dofile(L.get(), filename.c_str())) { lua_error(L.get()); } } diff --git a/sol/traits.hpp b/sol/traits.hpp index c86cce6d..ff5056b7 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -147,11 +147,11 @@ struct is_function_impl { template struct check_deducible_signature { template - static auto test( int ) -> decltype( &G::operator(), void( ) ); + static auto test(int) -> decltype(&G::operator(), void()); template - static auto test( ... ) -> struct nat; + static auto test(...) -> struct nat; - using type = std::is_void < decltype( test( 0 ) ) > ; + using type = std::is_void(0))>; }; } // detail diff --git a/sol/types.hpp b/sol/types.hpp index 4e6fae59..108f221e 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -39,19 +39,19 @@ using function_t = function_sig_t<>; struct upvalue_t { void* value; upvalue_t(void* data) : value(data) {} - operator void* () const { return value; } + operator void*() const { return value; } }; struct lightuserdata_t { void* value; - lightuserdata_t(void* data) : value(data) {} - operator void* () const { return value; } + lightuserdata_t(void* data) : value(data) {} + operator void*() const { return value; } }; -struct userdata_t { +struct userdata_t { void* value; - userdata_t(void* data) : value(data) {} - operator void* () const { return value; } + userdata_t(void* data) : value(data) {} + operator void*() const { return value; } }; enum class call_syntax { diff --git a/sol/userdata.hpp b/sol/userdata.hpp index 84c9ca1c..48ddb023 100644 --- a/sol/userdata.hpp +++ b/sol/userdata.hpp @@ -113,7 +113,7 @@ private: template static void match_constructor(lua_State* L, T* obj, call_syntax syntax, int argcount, types t, Args&&... args) { - if (argcount == sizeof...(CArgs)) { + if(argcount == sizeof...(CArgs)) { do_constructor(L, obj, syntax, argcount, t); return; } @@ -129,7 +129,7 @@ private: T* obj = static_cast(udata); match_constructor(L, obj, syntax, argcount - static_cast(syntax), typename identity::type()...); - if (luaL_newmetatable(L, std::addressof(meta[0])) == 1) { + if(luaL_newmetatable(L, std::addressof(meta[0])) == 1) { lua_pop(L, 1); std::string err = "Unable to get userdata metatable for "; err += meta; @@ -152,52 +152,52 @@ private: }; template - void build_cleanup () { + void build_cleanup() { cleanup = &base_function::userdata::gc; } template void build_function_tables(function_map_t*& index, function_map_t*& newindex) { int extracount = 0; - if (!indexmetafunctions.empty()) { - if (index == nullptr) { + if(!indexmetafunctions.empty()) { + if(index == nullptr) { auto idxptr = detail::make_unique>("__index", nullptr); index = &(idxptr->functions); functionnames.emplace_back("__index"); metafunctions.emplace_back(std::move(idxptr)); std::string& name = functionnames.back(); - metafunctiontable.push_back( { name.c_str(), &base_function::userdata::call } ); - ptrmetafunctiontable.push_back( { name.c_str(), &base_function::userdata::ref_call } ); + metafunctiontable.push_back({ name.c_str(), &base_function::userdata::call }); + ptrmetafunctiontable.push_back({ name.c_str(), &base_function::userdata::ref_call }); ++extracount; } auto& idx = *index; - for (auto&& namedfunc : indexmetafunctions ) { + for(auto&& namedfunc : indexmetafunctions) { idx.emplace(std::move(namedfunc.first), std::move(namedfunc.second)); } } - if (!newindexmetafunctions.empty()) { - if (newindex == nullptr) { + if(!newindexmetafunctions.empty()) { + if(newindex == nullptr) { auto idxptr = detail::make_unique>("__newindex", nullptr); newindex = &(idxptr->functions); functionnames.emplace_back("__newindex"); metafunctions.emplace_back(std::move(idxptr)); std::string& name = functionnames.back(); - if (extracount > 0) { - metafunctiontable.push_back( { name.c_str(), &base_function::userdata::call } ); - ptrmetafunctiontable.push_back( { name.c_str(), &base_function::userdata::ref_call } ); + if(extracount > 0) { + metafunctiontable.push_back({ name.c_str(), &base_function::userdata::call }); + ptrmetafunctiontable.push_back({ name.c_str(), &base_function::userdata::ref_call }); } else { - metafunctiontable.push_back( { name.c_str(), &base_function::userdata::call } ); - ptrmetafunctiontable.push_back( { name.c_str(), &base_function::userdata::ref_call } ); + metafunctiontable.push_back({ name.c_str(), &base_function::userdata::call }); + ptrmetafunctiontable.push_back({ name.c_str(), &base_function::userdata::ref_call }); } ++extracount; } auto& idx = *newindex; - for (auto&& namedfunc : newindexmetafunctions ) { + for(auto&& namedfunc : newindexmetafunctions) { idx.emplace(std::move(namedfunc.first), std::move(namedfunc.second)); } } - switch (extracount) { + switch(extracount) { case 2: build_cleanup(); break; @@ -262,14 +262,14 @@ private: bool build_function(std::false_type, function_map_t*& index, function_map_t*& newindex, std::string funcname, Fx&& func) { typedef typename std::decay::type function_type; auto metamethod = std::find(meta_function_names.begin(), meta_function_names.end(), funcname); - if (metamethod != meta_function_names.end()) { + if(metamethod != meta_function_names.end()) { functionnames.push_back(std::move(funcname)); std::string& name = functionnames.back(); auto indexmetamethod = std::find(meta_variable_names.begin(), meta_variable_names.end(), name); std::unique_ptr ptr(nullptr); - if (indexmetamethod != meta_variable_names.end()) { + if(indexmetamethod != meta_variable_names.end()) { auto idxptr = detail::make_unique>(name, func); - switch( std::distance(indexmetamethod, meta_variable_names.end()) ) { + switch(std::distance(indexmetamethod, meta_variable_names.end())) { case 0: index = &(idxptr->functions); break; @@ -296,8 +296,8 @@ private: template void build_function_tables(function_map_t*& index, function_map_t*& newindex, std::string funcname, Fx&& func, Args&&... args) { typedef typename std::is_member_object_pointer>::type is_variable; - static const std::size_t V = static_cast( !is_variable::value ); - if (build_function(is_variable(), index, newindex, std::move(funcname), std::forward(func))) { + static const std::size_t V = static_cast(!is_variable::value); + if(build_function(is_variable(), index, newindex, std::move(funcname), std::forward(func))) { build_function_tables(index, newindex, std::forward(args)...); } else { @@ -347,11 +347,11 @@ public: userdata(const char* name, constructors c, Args&&... args) : userdata(std::string(name), std::move(c), std::forward(args)...) {} - const std::string& name () const { + const std::string& name() const { return luaname; } - void push (lua_State* L) { + void push(lua_State* L) { // push pointer tables first, // but leave the regular T table on last // so it can be linked to a type for usage with `.new(...)` or `:new(...)` @@ -368,7 +368,7 @@ private: template static void push_metatable(lua_State* L, Meta&& metakey, MetaFuncs&& metafuncs, MetaFuncTable&& metafunctable) { luaL_newmetatable(L, std::addressof(metakey[0])); - if (metafunctable.size() > 1) { + if(metafunctable.size() > 1) { // regular functions accessed through __index semantics int up = push_upvalues(L, metafuncs); luaL_setfuncs(L, metafunctable.data(), up); @@ -376,7 +376,7 @@ private: } - void set_global_deleter (lua_State* L) { + void set_global_deleter(lua_State* L) { // Automatic deleter table -- stays alive until lua VM dies // even if the user calls collectgarbage() lua_createtable(L, 0, 0); @@ -390,13 +390,15 @@ private: } template - static int push_upvalues (lua_State* L, TCont&& cont) { + static int push_upvalues(lua_State* L, TCont&& cont) { int n = 0; - for (auto& c : cont) { - if (release) + for(auto& c : cont) { + if(release) { stack::push(L, c.release()); - else + } + else { stack::push(L, c.get()); + } ++n; } return n; @@ -406,12 +408,11 @@ private: namespace stack { template struct pusher> { - static void push (lua_State* L, userdata& user) { + static void push(lua_State* L, userdata& user) { user.push(L); } }; } // stack - } // sol #endif // SOL_USERDATA_HPP