object is now more flexible while still supporting the same semantics

indentation an spacing fixes for everything
This commit is contained in:
ThePhD 2015-10-20 21:38:28 -04:00
parent 8e0cc99215
commit 93d532094e
13 changed files with 72 additions and 47 deletions

View File

@ -59,7 +59,7 @@ inline std::string demangle(const std::type_info& id) {
while(found != std::string::npos) {
realname.erase(found, removals[r].size());
found = realname.find(removals[r]);
}
}
}
for(std::size_t r = 0; r < replacements.size(); r+=2) {

View File

@ -34,10 +34,10 @@
namespace sol {
namespace detail {
template <typename T>
struct SOL_DEPRECATED deprecate_type {
using type = T;
};
template <typename T>
struct SOL_DEPRECATED deprecate_type {
using type = T;
};
} // detail
} // sol

View File

@ -110,11 +110,11 @@ private:
function_result invoke(indices<>, types<>, std::ptrdiff_t n) const {
const int stacksize = lua_gettop(state());
const int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1);
const int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1);
luacall(n, LUA_MULTRET);
const int poststacksize = lua_gettop(state());
const int returncount = poststacksize - firstreturn;
return function_result(state(), firstreturn + 1, returncount);
return function_result(state(), firstreturn + 1, returncount);
}
public:
@ -172,7 +172,7 @@ struct pusher<function_sig_t<Sigs...>> {
template<typename Sig>
static void set(lua_State* L, Sig* fxptr){
set_fx(std::false_type(), L, fxptr);
set_fx(std::false_type(), L, fxptr);
}
template<typename... Args, typename R, typename C, typename T>

View File

@ -47,7 +47,7 @@ struct functor {
functor(FxArgs&&... fxargs): item(nullptr), invocation(std::forward<FxArgs>(fxargs)...) {}
bool check () const {
return invocation != nullptr;
return invocation != nullptr;
}
template<typename... Args>

View File

@ -24,6 +24,7 @@
#include "reference.hpp"
#include "stack.hpp"
#include "function.hpp"
namespace sol {
class object : public reference {
@ -32,10 +33,13 @@ public:
object() = default;
template<typename T>
auto as() const -> decltype(stack::get<T>(state())) {
auto as() const -> decltype(stack::get<T>(state())) const {
push();
type actual = stack::get<type>(state());
type_assert(state(), -1, type_of<T>(), actual);
// This code is actually present
// in almost all of the type-getters,
// and it thus insanely redundant
// type_assert(state(), -1, type_of<T>(), actual);
return stack::pop<T>(state());
}
@ -46,25 +50,44 @@ public:
return (expected == actual) || (expected == type::poly);
}
explicit operator bool() const {
return !is<nil_t>();
bool valid() const {
return !this->is<nil_t>();
}
operator const char* () const {
return this->as<const char*>();
}
template<typename T, EnableIf<Not<std::is_same<Unqualified<T>, const char*>>, Not<std::is_same<Unqualified<T>, char>>, Not<std::is_same<Unqualified<T>, std::string>>, Not<std::is_same<Unqualified<T>, std::initializer_list<char>>>> = 0>
operator T () const {
return this->as<T>();
}
template<typename... Ret, typename... Args>
stack::get_return_or<function_result, Ret...> call( Args&&... args ) {
return this->as<function>()(types<Ret...>(), std::forward<Args>( args )...);
}
template<typename... Args>
function_result operator()( Args&&... args ) {
return this->as<function>()(std::forward<Args>( args )...);
}
};
inline bool operator==(const object& lhs, const nil_t&) {
return lhs.is<nil_t>();
return !lhs.valid();
}
inline bool operator==(const nil_t&, const object& rhs) {
return rhs.is<nil_t>();
return !rhs.valid();
}
inline bool operator!=(const object& lhs, const nil_t&) {
return !lhs.is<nil_t>();
return lhs.valid();
}
inline bool operator!=(const nil_t&, const object& rhs) {
return !rhs.is<nil_t>();
return rhs.valid();
}
} // sol

View File

@ -31,18 +31,13 @@ template<typename Table, typename Key>
struct proxy {
private:
Table& tbl;
Key& key;
If<std::is_array<Unqualified<Key>>, Key&, Unqualified<Key>> key;
public:
template<typename T>
proxy(Table& table, T&& key) : tbl(table), key(std::forward<T>(key)) {}
template<typename T>
T get() const {
return tbl.template get<T>(key);
}
template<typename T>
proxy& set(T&& item) {
tbl.set(key, std::forward<T>(item));
@ -56,13 +51,20 @@ public:
}
template<typename U, EnableIf<Function<Unqualified<U>>> = 0>
void operator=(U&& other) {
proxy& operator=(U&& other) {
tbl.set_function(key, std::forward<U>(other));
return *this;
}
template<typename U, DisableIf<Function<Unqualified<U>>> = 0>
void operator=(U&& other) {
proxy& operator=(U&& other) {
tbl.set(key, std::forward<U>(other));
return *this;
}
template<typename T>
T get() const {
return tbl.template get<T>( key );
}
operator const char* () const {

View File

@ -43,7 +43,7 @@ inline auto resolve_f(std::true_type, F&& f)
template<typename F>
inline 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");
"Cannot use no-template-parameter call with an overloaded functor: specify the signature");
}
template<typename F, typename U = Unqualified<F>>

View File

@ -378,7 +378,7 @@ struct pusher {
template<typename U = T, EnableIf<std::is_base_of<reference, U>> = 0>
static int push(lua_State*, T& ref) {
return ref.push();
return ref.push();
}
template<typename U = Unqualified<T>, EnableIf<Not<has_begin_end<U>>, Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>

View File

@ -153,7 +153,7 @@ public:
template<typename... Args, typename... Keys>
auto get(Keys&&... keys) const
-> decltype(global.get<Args...>(std::forward<Keys>(keys)...)) {
return global.get<Args...>(std::forward<Keys>(keys)...);
return global.get<Args...>(std::forward<Keys>(keys)...);
}
template<typename T, typename U>

View File

@ -58,7 +58,7 @@ public:
template<typename... Ret, typename... Keys>
stack::get_return<Ret...> get( Keys&&... keys ) const {
return tuple_get(types<Ret...>(), build_indices<sizeof...(Ret)>(), std::tie(keys...));
return tuple_get(types<Ret...>(), build_indices<sizeof...(Ret)>(), std::tie(keys...));
}
template<typename T, typename U>
@ -114,16 +114,16 @@ public:
size_t result = lua_rawlen(state(), -1);
pop();
return result;
}
template<typename T>
}
template<typename T>
proxy<table, T> operator[]( T&& key ) {
return proxy<table, T>( *this, std::forward<T>( key ) );
}
template<typename T>
return proxy<table, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<const table, T> operator[]( T&& key ) const {
return proxy<const table, T>( *this, std::forward<T>( key ) );
return proxy<const table, T>( *this, std::forward<T>( key ) );
}
void pop(int n = 1) const noexcept {

View File

@ -286,8 +286,8 @@ struct member_traits : detail::member_traits<Signature> {
struct has_begin_end_impl {
template<typename T, typename U = Unqualified<T>,
typename B = decltype(std::declval<U&>().begin()),
typename E = decltype(std::declval<U&>().end())>
typename B = decltype(std::declval<U&>().begin()),
typename E = decltype(std::declval<U&>().end())>
static std::true_type test(int);
template<typename...>
@ -299,9 +299,9 @@ struct has_begin_end : decltype(has_begin_end_impl::test<T>(0)) {};
struct has_key_value_pair_impl {
template<typename T, typename U = Unqualified<T>,
typename V = typename U::value_type,
typename F = decltype(std::declval<V&>().first),
typename S = decltype(std::declval<V&>().second)>
typename V = typename U::value_type,
typename F = decltype(std::declval<V&>().first),
typename S = decltype(std::declval<V&>().second)>
static std::true_type test(int);
template<typename...>

View File

@ -73,7 +73,7 @@ enum class type : int {
userdata = LUA_TUSERDATA,
lightuserdata = LUA_TLIGHTUSERDATA,
table = LUA_TTABLE,
poly = none | nil | string | number | thread |
poly = none | nil | string | number | thread |
table | boolean | function | userdata | lightuserdata
};
@ -96,14 +96,14 @@ inline void type_error(lua_State* L, type expected, type actual) {
inline void type_assert(lua_State* L, int index, type expected, type actual) {
if (expected != type::poly && expected != actual) {
type_panic(L, index, expected, actual);
type_panic(L, index, expected, actual);
}
}
inline void type_assert(lua_State* L, int index, type expected) {
int actual = lua_type(L, index);
if(expected != type::poly && static_cast<int>(expected) != actual) {
type_error(L, static_cast<int>(expected), actual);
type_error(L, static_cast<int>(expected), actual);
}
}

View File

@ -358,11 +358,11 @@ public:
// but leave the regular T table on last
// so it can be linked to a type for usage with `.new(...)` or `:new(...)`
push_metatable(L, usertype_traits<T*>::metatable,
metafunctions, ptrmetafunctiontable);
metafunctions, ptrmetafunctiontable);
lua_pop(L, 1);
push_metatable(L, usertype_traits<T>::metatable,
metafunctions, metafunctiontable);
metafunctions, metafunctiontable);
set_global_deleter(L);
return 1;
}