Minor stylistic changes to be consistent

This commit is contained in:
Rapptz 2013-12-12 05:07:58 -05:00
parent 61e49d9829
commit fdf145ecd8
2 changed files with 32 additions and 38 deletions

View File

@ -28,15 +28,15 @@
namespace sol { namespace sol {
namespace detail { namespace detail {
template<typename T, std::size_t n> template<typename T, std::size_t N>
void get_upvalue_ptr(lua_State* L, T*& data, std::size_t datasize, std::array<void*, n> voiddata, int& upvalue) { void get_upvalue_ptr(lua_State* L, T*& data, std::size_t datasize, std::array<void*, N> voiddata, int& upvalue) {
for (std::size_t i = 0, d = 0; d < datasize; ++i, d += sizeof(void*)) { 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<T*>(static_cast<void*>(voiddata.data())); data = reinterpret_cast<T*>(static_cast<void*>(voiddata.data()));
} }
template<typename T, std::size_t n> template<typename T, std::size_t N>
void get_upvalue_ptr(lua_State* L, T*& data, std::array<void*, n> voiddata, int& upvalue) { void get_upvalue_ptr(lua_State* L, T*& data, std::array<void*, N> voiddata, int& upvalue) {
get_upvalue_ptr(L, data, sizeof(T), voiddata, upvalue); get_upvalue_ptr(L, data, sizeof(T), voiddata, upvalue);
} }
template<typename T> template<typename T>
@ -50,9 +50,9 @@ template<typename T>
void get_upvalue(lua_State* L, T& data, int& upvalue) { 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*); const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*);
typedef std::array<void*, data_t_count> data_t; typedef std::array<void*, data_t_count> data_t;
data_t voiddata{ { } }; 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 ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); voiddata[i] = lua_touserdata(L, lua_upvalueindex(upvalue++));
} }
data = *reinterpret_cast<T*>(static_cast<void*>(voiddata.data())); data = *reinterpret_cast<T*>(static_cast<void*>(voiddata.data()));
} }
@ -97,14 +97,14 @@ struct static_object_lua_func {
template<typename... Args> template<typename... Args>
static int typed_call(types<void>, types<Args...>, T& item, fx_t& ifx, lua_State* L) { static int typed_call(types<void>, types<Args...>, T& item, fx_t& ifx, lua_State* L) {
auto fx = [ &item, &ifx ] (Args&&... args) { (item.*ifx)(std::forward<Args>(args)...); }; auto fx = [&item, &ifx](Args&&... args) { (item.*ifx)(std::forward<Args>(args)...); };
stack::pop_call(L, fx, types<Args...>()); stack::pop_call(L, fx, types<Args...>());
return 0; return 0;
} }
template<typename TR, typename... Args> template<typename TR, typename... Args>
static int typed_call(types<TR>, types<Args...>, T& item, fx_t& ifx, lua_State* L) { static int typed_call(types<TR>, types<Args...>, 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>(args)...); return (item.*ifx)(std::forward<Args>(args)...);
}; };
auto r = stack::pop_call(L, fx, types<Args...>()); auto r = stack::pop_call(L, fx, types<Args...>());
@ -114,7 +114,7 @@ struct static_object_lua_func {
template<typename... TRn, typename... Args> template<typename... TRn, typename... Args>
static int typed_call(types<TRn...>, types<Args...>, T& item, fx_t& ifx, lua_State* L) { static int typed_call(types<TRn...>, types<Args...>, T& item, fx_t& ifx, lua_State* L) {
auto fx = [ &item, &ifx ] (Args&&... args) -> std::tuple<TRn...> { return (item.*ifx)(std::forward<Args>(args)...); }; auto fx = [&item, &ifx](Args&&... args) -> std::tuple<TRn...> { return (item.*ifx)(std::forward<Args>(args)...); };
auto r = stack::pop_call(L, fx, types<Args...>()); auto r = stack::pop_call(L, fx, types<Args...>());
stack::push(L, std::move(r)); stack::push(L, std::move(r));
return sizeof...(TRn); return sizeof...(TRn);
@ -124,10 +124,10 @@ struct static_object_lua_func {
const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*);
typedef std::array<void*, data_t_count> data_t; typedef std::array<void*, data_t_count> data_t;
int upvalue = 1; int upvalue = 1;
data_t data = { { } }; data_t data = {{}};
fx_t* fxptr; fx_t* fxptr;
for (std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof(void*)) { for (std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof(void*)) {
data[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); data[i] = lua_touserdata(L, lua_upvalueindex(upvalue++));
} }
fxptr = reinterpret_cast<fx_t*>(static_cast<void*>(data.data())); fxptr = reinterpret_cast<fx_t*>(static_cast<void*>(data.data()));
fx_t& mem_ptr = *fxptr; fx_t& mem_ptr = *fxptr;
@ -147,7 +147,7 @@ struct lua_func {
void** pinheritancedata = static_cast<void**>(lua_touserdata(L, lua_upvalueindex(1))); void** pinheritancedata = static_cast<void**>(lua_touserdata(L, lua_upvalueindex(1)));
void* inheritancedata = *pinheritancedata; void* inheritancedata = *pinheritancedata;
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");
lua_func* pfx = static_cast<lua_func*>(inheritancedata); lua_func* pfx = static_cast<lua_func*>(inheritancedata);
lua_func& fx = *pfx; lua_func& fx = *pfx;
int r = fx(L); int r = fx(L);
@ -164,10 +164,10 @@ struct lua_func {
} }
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");
} }
virtual ~lua_func() {}; virtual ~lua_func() {}
}; };
template<typename TFx> template<typename TFx>
@ -196,9 +196,7 @@ struct lambda_lua_func : public lua_func {
return sizeof...(TRn); return sizeof...(TRn);
} }
~lambda_lua_func() { ~lambda_lua_func() {}
}
}; };
template<typename TFx, typename T = TFx, bool is_member_pointer = std::is_member_function_pointer<TFx>::value> template<typename TFx, typename T = TFx, bool is_member_pointer = std::is_member_function_pointer<TFx>::value>
@ -227,9 +225,7 @@ struct explicit_lua_func : public lua_func {
return sizeof...(TRn); return sizeof...(TRn);
} }
~explicit_lua_func() { ~explicit_lua_func() {}
}
}; };
template<typename TFx, typename T> template<typename TFx, typename T>
@ -269,9 +265,7 @@ struct explicit_lua_func<TFx, T, true> : public lua_func {
return sizeof...(TRn); return sizeof...(TRn);
} }
~explicit_lua_func() { ~explicit_lua_func() {}
}
}; };
} // sol } // sol

View File

@ -206,7 +206,7 @@ inline int push_user(lua_State* L, T& item) {
typedef std::array<void*, data_t_count> data_t; typedef std::array<void*, data_t_count> data_t;
data_t data{{}}; 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); push(L, data);
return data_t_count; return data_t_count;
} }
@ -215,7 +215,7 @@ namespace detail {
template<typename T, std::size_t... I> template<typename T, std::size_t... I>
inline void push(lua_State* L, indices<I...>, const T& tuplen) { inline void push(lua_State* L, indices<I...>, const T& tuplen) {
using swallow = char[]; using swallow = char[];
void(swallow{ '\0', (sol::stack::push(L, std::get<I>(tuplen)), '\0')... }); void(swallow{'\0', (sol::stack::push(L, std::get<I>(tuplen)), '\0')... });
} }
template<typename F, typename... Vs> template<typename F, typename... Vs>
@ -245,7 +245,7 @@ inline auto pop_call(lua_State* L, TFx&& fx, types<Args...>) -> decltype(detail:
template<typename... Args> template<typename... Args>
void push_args(lua_State* L, Args&&... args) { void push_args(lua_State* L, Args&&... args) {
using swallow = char[]; using swallow = char[];
void(swallow{ '\0', (stack::push(L, std::forward<Args>(args)), '\0')... }); void(swallow{'\0', (stack::push(L, std::forward<Args>(args)), '\0')... });
} }
} // stack } // stack
} // sol } // sol