Formatting changes.

This commit is contained in:
Rapptz 2014-08-10 20:49:34 -04:00
parent 2a5b800286
commit da76793c30
11 changed files with 118 additions and 118 deletions

View File

@ -27,13 +27,13 @@
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)
if(i != 1) {
visual += " | ";
}
visual += type_name(L, stack::get<type>(L, i));
}
return visual;
@ -46,7 +46,6 @@ inline void print_stack (lua_State* L) {
inline void print_section(const std::string& message, lua_State* L) {
std::cout << "-- " << message << " -- [ " << dump_types(L) << " ]" << std::endl;
}
} // debug
} // sol

View File

@ -26,7 +26,6 @@
#include "traits.hpp"
namespace sol {
struct default_construct {
template<typename T, typename... Args>
void operator()(T&& obj, Args&&... args) const {
@ -34,7 +33,6 @@ struct default_construct {
alloc.construct(obj, std::forward<Args>(args)...);
}
};
} // sol
#endif // SOL_DEFAULT_CONSTRUCTOR_HPP

View File

@ -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);
}

View File

@ -442,8 +442,9 @@ struct userdata_function : public userdata_function_core<Function, Tp> {
template<typename Tx>
int fx_call(lua_State* L) {
this->fx.item = detail::get_ptr(stack::get<Tx>(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<base_t&>(*this)(tuple_types<return_type>(), args_type(), L);
}
@ -470,8 +471,10 @@ struct userdata_variable_function : public userdata_function_core<Function, Tp>
template<typename Tx>
int fx_call(lua_State* L) {
this->fx.item = detail::get_ptr(stack::get<Tx>(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) {
case 2:
@ -514,25 +517,23 @@ struct userdata_indexing_function : public userdata_function_core<Function, Tp>
if(function != functions.end()) {
if(function->second.second) {
stack::push<upvalue_t>(L, function->second.first.get());
if (std::is_same<T*, Tx>::value)
if(std::is_same<T*, Tx>::value) {
stack::push(L, &base_function::userdata<0>::ref_call, 1);
else
stack::push(L, &base_function::userdata<0>::call, 1);
return 1;
}
else {
if (std::is_same<T*, Tx>::value)
stack::push(L, &base_function::userdata<0>::call, 1);
}
return 1;
}
else if(std::is_same<T*, Tx>::value) {
return (*function->second.first)(L, detail::ref_call);
else
}
else {
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);
throw error("invalid indexing \"" + accessor + "\" on type: " + name);
}
this->fx.item = detail::get_ptr(stack::get<Tx>(L, 1));
return static_cast<base_t&>(*this)(tuple_types<return_type>(), args_type(), L);

View File

@ -27,66 +27,66 @@
namespace sol {
namespace detail {
template<class R, class... Args, class F, class = typename std::result_of<Unqualified<F>( Args... )>::type>
template<typename R, typename... Args, typename F, typename = typename std::result_of<Unqualified<F>(Args...)>::type>
auto resolve_i(types<R(Args...)>, F&&)->R(Unqualified<F>::*)(Args...) {
typedef R( Sig )( Args... );
using Sig = R(Args...);
typedef Unqualified<F> Fu;
return static_cast<Sig Fu::*>(&Fu::operator());
}
template<class F>
auto resolve_f( std::true_type, F&& f ) -> decltype( resolve_i( types<function_signature_t<decltype( &Unqualified<F>::operator() )>>( ), std::forward<F>( f ) ) ) {
typedef Unqualified<F> Fu;
return resolve_i( types<function_signature_t<decltype( &Fu::operator() )>>( ), std::forward<F>( f ) );
template<typename F, typename U = Unqualified<F>>
auto resolve_f(std::true_type, F&& f) -> decltype(resolve_i(types<function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
return resolve_i(types<function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
}
template<class F>
template<typename F>
void resolve_f(std::false_type, F&&) {
static_assert( has_deducible_signature<F>::value, "Cannot use no-template-parameter call with an overloaded functor: specify the signature" );
static_assert(has_deducible_signature<F>::value,
"Cannot use no-template-parameter call with an overloaded functor: specify the signature");
}
template<class F>
auto resolve_i( types<>, F&& f ) -> decltype( resolve_f( has_deducible_signature<Unqualified<F>> {}, std::forward<F>( f ) ) ) {
return resolve_f( has_deducible_signature<Unqualified<F>> {}, std::forward<F>( f ) );
template<typename F, typename U = Unqualified<F>>
auto resolve_i(types<>, F&& f) -> decltype(resolve_f(has_deducible_signature<U> {}, std::forward<F>(f))) {
return resolve_f(has_deducible_signature<U> {}, std::forward<F>(f));
}
template<class... Args, class F, class R = typename std::result_of<F&( Args... )>::type>
template<typename... Args, typename F, typename R = typename std::result_of<F&(Args...)>::type>
auto resolve_i(types<Args...>, F&& f) -> decltype( resolve_i(types<R(Args...)>(), std::forward<F>(f))) {
return resolve_i(types<R(Args...)>(), std::forward<F>(f));
}
template<class Sig, class C>
template<typename Sig, typename C>
Sig C::* resolve_v(std::false_type, Sig C::* mem_func_ptr) {
return mem_func_ptr;
}
template<class Sig, class C>
template<typename Sig, typename C>
Sig C::* resolve_v(std::true_type, Sig C::* mem_variable_ptr) {
return mem_variable_ptr;
}
} // detail
template<class... Args, class R>
template<typename... Args, typename R>
auto resolve(R fun_ptr(Args...)) -> R(*)(Args...) {
return fun_ptr;
}
template<class Sig>
template<typename Sig>
Sig* resolve(Sig* fun_ptr) {
return fun_ptr;
}
template<class... Args, class R, class C>
template<typename... Args, typename R, typename C>
auto resolve(R(C::*mem_ptr)(Args...)) -> R(C::*)(Args...) {
return mem_ptr;
}
template<class Sig, class C>
template<typename Sig, typename C>
Sig C::* resolve(Sig C::* mem_ptr) {
return detail::resolve_v(std::is_member_object_pointer<Sig C::*>(), mem_ptr);
}
template<class... Sig, class F>
template<typename... Sig, typename F>
auto resolve(F&& f) -> decltype(detail::resolve_i(types<Sig...>(), std::forward<F>(f))) {
return detail::resolve_i(types<Sig...>(), std::forward<F>(f));
}

View File

@ -160,8 +160,9 @@ struct getter<const char*> {
template<>
struct getter<nil_t> {
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{ };
}
};

View File

@ -393,10 +393,12 @@ private:
static int push_upvalues(lua_State* L, TCont&& cont) {
int n = 0;
for(auto& c : cont) {
if (release)
if(release) {
stack::push<upvalue_t>(L, c.release());
else
}
else {
stack::push<upvalue_t>(L, c.get());
}
++n;
}
return n;
@ -411,7 +413,6 @@ struct pusher<userdata<T>> {
}
};
} // stack
} // sol
#endif // SOL_USERDATA_HPP