diff --git a/sol/lua_function.hpp b/sol/lua_function.hpp index d98e553b..c29b8963 100644 --- a/sol/lua_function.hpp +++ b/sol/lua_function.hpp @@ -28,15 +28,15 @@ namespace sol { namespace detail { -template -void get_upvalue_ptr(lua_State* L, T*& data, std::size_t datasize, std::array voiddata, int& upvalue) { +template +void get_upvalue_ptr(lua_State* L, T*& data, std::size_t datasize, std::array voiddata, int& upvalue) { for (std::size_t i = 0, d = 0; d < datasize; ++i, d += sizeof(void*)) { - voiddata[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + voiddata[i] = lua_touserdata(L, lua_upvalueindex(upvalue++)); } data = reinterpret_cast(static_cast(voiddata.data())); } -template -void get_upvalue_ptr(lua_State* L, T*& data, std::array voiddata, int& upvalue) { +template +void get_upvalue_ptr(lua_State* L, T*& data, std::array voiddata, int& upvalue) { get_upvalue_ptr(L, data, sizeof(T), voiddata, upvalue); } template @@ -50,9 +50,9 @@ template void get_upvalue(lua_State* L, T& data, int& upvalue) { const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*); typedef std::array data_t; - data_t voiddata{ { } }; + data_t voiddata{{}}; for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { - voiddata[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + voiddata[i] = lua_touserdata(L, lua_upvalueindex(upvalue++)); } data = *reinterpret_cast(static_cast(voiddata.data())); } @@ -97,14 +97,14 @@ struct static_object_lua_func { template static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { - auto fx = [ &item, &ifx ] (Args&&... args) { (item.*ifx)(std::forward(args)...); }; + auto fx = [&item, &ifx](Args&&... args) { (item.*ifx)(std::forward(args)...); }; stack::pop_call(L, fx, types()); return 0; } template static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { - auto fx = [ &item, &ifx ] (Args&&... args) -> TR { + auto fx = [&item, &ifx](Args&&... args) -> TR { return (item.*ifx)(std::forward(args)...); }; auto r = stack::pop_call(L, fx, types()); @@ -114,26 +114,26 @@ struct static_object_lua_func { template static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { - auto fx = [ &item, &ifx ] (Args&&... args) -> std::tuple { return (item.*ifx)(std::forward(args)...); }; + auto fx = [&item, &ifx](Args&&... args) -> std::tuple { return (item.*ifx)(std::forward(args)...); }; auto r = stack::pop_call(L, fx, types()); stack::push(L, std::move(r)); return sizeof...(TRn); } static int call(lua_State* L) { - const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); - typedef std::array data_t; - int upvalue = 1; - data_t data = { { } }; - fx_t* fxptr; - for (std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof(void*)) { - data[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); - } - fxptr = reinterpret_cast(static_cast(data.data())); - fx_t& mem_ptr = *fxptr; - void* objectdata = lua_touserdata(L, lua_upvalueindex(upvalue++)); - T& obj = *static_cast(objectdata); - int r = typed_call(tuple_types(), typename fx_traits::args_type(), obj, mem_ptr, L); + const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); + typedef std::array data_t; + int upvalue = 1; + data_t data = {{}}; + fx_t* fxptr; + for (std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof(void*)) { + data[i] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + } + fxptr = reinterpret_cast(static_cast(data.data())); + fx_t& mem_ptr = *fxptr; + void* objectdata = lua_touserdata(L, lua_upvalueindex(upvalue++)); + T& obj = *static_cast(objectdata); + int r = typed_call(tuple_types(), typename fx_traits::args_type(), obj, mem_ptr, L); return r; } @@ -147,7 +147,7 @@ struct lua_func { void** pinheritancedata = static_cast(lua_touserdata(L, lua_upvalueindex(1))); void* inheritancedata = *pinheritancedata; 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"); lua_func* pfx = static_cast(inheritancedata); lua_func& fx = *pfx; int r = fx(L); @@ -164,10 +164,10 @@ struct lua_func { } 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"); } - virtual ~lua_func() {}; + virtual ~lua_func() {} }; template @@ -196,9 +196,7 @@ struct lambda_lua_func : public lua_func { return sizeof...(TRn); } - ~lambda_lua_func() { - - } + ~lambda_lua_func() {} }; template::value> @@ -227,9 +225,7 @@ struct explicit_lua_func : public lua_func { return sizeof...(TRn); } - ~explicit_lua_func() { - - } + ~explicit_lua_func() {} }; template @@ -269,9 +265,7 @@ struct explicit_lua_func : public lua_func { return sizeof...(TRn); } - ~explicit_lua_func() { - - } + ~explicit_lua_func() {} }; } // sol diff --git a/sol/stack.hpp b/sol/stack.hpp index b301072a..40975cf7 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -206,7 +206,7 @@ inline int push_user(lua_State* L, T& item) { typedef std::array data_t; data_t data{{}}; - std::memcpy(std::addressof(data[ 0 ]), std::addressof(item), itemsize); + std::memcpy(std::addressof(data[0]), std::addressof(item), itemsize); push(L, data); return data_t_count; } @@ -215,7 +215,7 @@ namespace detail { template inline void push(lua_State* L, indices, const T& tuplen) { using swallow = char[]; - void(swallow{ '\0', (sol::stack::push(L, std::get(tuplen)), '\0')... }); + void(swallow{'\0', (sol::stack::push(L, std::get(tuplen)), '\0')... }); } template @@ -245,7 +245,7 @@ inline auto pop_call(lua_State* L, TFx&& fx, types) -> decltype(detail: template void push_args(lua_State* L, Args&&... args) { using swallow = char[]; - void(swallow{ '\0', (stack::push(L, std::forward(args)), '\0')... }); + void(swallow{'\0', (stack::push(L, std::forward(args)), '\0')... }); } } // stack } // sol