mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Clearer names for some of the exposed classes.
This commit is contained in:
parent
c78f8b3292
commit
7402b1bc95
|
@ -44,7 +44,7 @@ struct constructor_match {
|
||||||
template <bool b, typename Fx, std::size_t I, typename... R, typename... Args>
|
template <bool b, typename Fx, std::size_t I, typename... R, typename... Args>
|
||||||
int operator()(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) const {
|
int operator()(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) const {
|
||||||
default_construct func{};
|
default_construct func{};
|
||||||
return stack::typed_call<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start, obj);
|
return stack::call_into_lua<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start, obj);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // detail
|
} // detail
|
||||||
|
@ -120,7 +120,7 @@ struct usertype_constructor_function : base_function {
|
||||||
userdataref.pop();
|
userdataref.pop();
|
||||||
|
|
||||||
auto& func = std::get<I>(overloads);
|
auto& func = std::get<I>(overloads);
|
||||||
stack::typed_call<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start, function_detail::implicit_wrapper<T>(obj));
|
stack::call_into_lua<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start, function_detail::implicit_wrapper<T>(obj));
|
||||||
|
|
||||||
userdataref.push();
|
userdataref.push();
|
||||||
luaL_getmetatable(L, &meta[0]);
|
luaL_getmetatable(L, &meta[0]);
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct member_function : public base_function {
|
||||||
member_function(Tm&& m, Args&&... args): fx(std::forward<Tm>(m), std::forward<Args>(args)...) {}
|
member_function(Tm&& m, Args&&... args): fx(std::forward<Tm>(m), std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
virtual int operator()(lua_State* L) override {
|
virtual int operator()(lua_State* L) override {
|
||||||
return stack::typed_call(meta::tuple_types<return_type>(), args_types(), fx, L, 1);
|
return stack::call_into_lua(meta::tuple_types<return_type>(), args_types(), fx, L, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // function_detail
|
} // function_detail
|
||||||
|
|
|
@ -96,7 +96,7 @@ struct overloaded_function : base_function {
|
||||||
template <bool b, typename Fx, std::size_t I, typename... R, typename... Args>
|
template <bool b, typename Fx, std::size_t I, typename... R, typename... Args>
|
||||||
int call(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
int call(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
||||||
auto& func = std::get<I>(overloads);
|
auto& func = std::get<I>(overloads);
|
||||||
return stack::typed_call<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start);
|
return stack::call_into_lua<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int operator()(lua_State* L) override {
|
virtual int operator()(lua_State* L) override {
|
||||||
|
@ -117,7 +117,7 @@ struct usertype_overloaded_function : base_function {
|
||||||
int call(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
int call(meta::Bool<b>, types<Fx>, Index<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
||||||
auto& func = std::get<I>(overloads);
|
auto& func = std::get<I>(overloads);
|
||||||
func.item = detail::ptr(stack::get<T>(L, 1));
|
func.item = detail::ptr(stack::get<T>(L, 1));
|
||||||
return stack::typed_call<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start);
|
return stack::call_into_lua<b ? false : stack::stack_detail::default_check_arguments>(r, a, func, L, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int operator()(lua_State* L) override {
|
virtual int operator()(lua_State* L) override {
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct static_function {
|
||||||
static int call(lua_State* L) {
|
static int call(lua_State* L) {
|
||||||
auto udata = stack::stack_detail::get_as_upvalues<function_type*>(L);
|
auto udata = stack::stack_detail::get_as_upvalues<function_type*>(L);
|
||||||
function_type* fx = udata.first;
|
function_type* fx = udata.first;
|
||||||
int r = stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
|
int r = stack::call_into_lua(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ struct static_member_function {
|
||||||
function_type& memfx = memberdata.first;
|
function_type& memfx = memberdata.first;
|
||||||
T& item = *objdata.first;
|
T& item = *objdata.first;
|
||||||
auto fx = [&item, &memfx](auto&&... args) -> typename traits_type::return_type { return (item.*memfx)(std::forward<decltype(args)>(args)...); };
|
auto fx = [&item, &memfx](auto&&... args) -> typename traits_type::return_type { return (item.*memfx)(std::forward<decltype(args)>(args)...); };
|
||||||
return stack::typed_call(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
|
return stack::call_into_lua(meta::tuple_types<typename traits_type::return_type>(), typename traits_type::args_type(), fx, L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int operator()(lua_State* L) {
|
int operator()(lua_State* L) {
|
||||||
|
|
|
@ -27,19 +27,19 @@
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace stack {
|
namespace stack {
|
||||||
template <bool top_level, typename T>
|
template <bool top_level, typename T>
|
||||||
struct push_pop {
|
struct push_popper {
|
||||||
T t;
|
T t;
|
||||||
push_pop (T x) : t(x) { t.push(); }
|
push_popper (T x) : t(x) { t.push(); }
|
||||||
~push_pop() { t.pop(); }
|
~push_popper() { t.pop(); }
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct push_pop<true, T> {
|
struct push_popper<true, T> {
|
||||||
push_pop (T) {}
|
push_popper (T) {}
|
||||||
~push_pop() {}
|
~push_popper() {}
|
||||||
};
|
};
|
||||||
template <bool top_level = false, typename T>
|
template <bool top_level = false, typename T>
|
||||||
push_pop<top_level, T> push_popper(T&& x) {
|
push_popper<top_level, T> push_pop(T&& x) {
|
||||||
return push_pop<top_level, T>(std::forward<T>(x));
|
return push_popper<top_level, T>(std::forward<T>(x));
|
||||||
}
|
}
|
||||||
} // stack
|
} // stack
|
||||||
|
|
||||||
|
|
|
@ -831,11 +831,6 @@ inline R call(types<R> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&...
|
||||||
return call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
return call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
|
|
||||||
inline R top_call(types<R> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
|
|
||||||
return call<check_args>(tr, ta, L, static_cast<int>(lua_gettop(L) - sizeof...(Args)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
template <bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
||||||
inline void call(types<void> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
|
inline void call(types<void> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
|
||||||
typedef typename types<Args...>::indices args_indices;
|
typedef typename types<Args...>::indices args_indices;
|
||||||
|
@ -847,13 +842,18 @@ inline void call(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArg
|
||||||
call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
call<check_args>(tr, ta, L, 1, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
|
||||||
|
inline R call_from_top(types<R> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
|
||||||
|
return call<check_args>(tr, ta, L, static_cast<int>(lua_gettop(L) - sizeof...(Args)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
template <bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
template <bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
||||||
inline void top_call(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
|
inline void call_from_top(types<void> tr, types<Args...> ta, lua_State* L, Fx&& fx, FxArgs&&... args) {
|
||||||
call<check_args>(tr, ta, L, static_cast<int>(lua_gettop(L) - sizeof...(Args)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
call<check_args>(tr, ta, L, static_cast<int>(lua_gettop(L) - sizeof...(Args)), std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
template<bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
||||||
inline int typed_call(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
|
inline int call_into_lua(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
|
||||||
call<check_args>(tr, ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
|
call<check_args>(tr, ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
|
||||||
int nargs = static_cast<int>(sizeof...(Args));
|
int nargs = static_cast<int>(sizeof...(Args));
|
||||||
lua_pop(L, nargs);
|
lua_pop(L, nargs);
|
||||||
|
@ -861,7 +861,7 @@ inline int typed_call(types<void> tr, types<Args...> ta, Fx&& fx, lua_State* L,
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool check_args = stack_detail::default_check_arguments, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::Not<std::is_void<Ret0>>::value>>
|
template<bool check_args = stack_detail::default_check_arguments, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::Not<std::is_void<Ret0>>::value>>
|
||||||
inline int typed_call(types<Ret0, Ret...>, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
|
inline int call_into_lua(types<Ret0, Ret...>, types<Args...> ta, Fx&& fx, lua_State* L, int start, FxArgs&&... fxargs) {
|
||||||
decltype(auto) r = call<check_args>(types<meta::return_type_t<Ret0, Ret...>>(), ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
|
decltype(auto) r = call<check_args>(types<meta::return_type_t<Ret0, Ret...>>(), ta, L, start, fx, std::forward<FxArgs>(fxargs)...);
|
||||||
int nargs = static_cast<int>(sizeof...(Args));
|
int nargs = static_cast<int>(sizeof...(Args));
|
||||||
lua_pop(L, nargs);
|
lua_pop(L, nargs);
|
||||||
|
|
|
@ -211,15 +211,6 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
table create_table(int narr = 0, int nrec = sizeof...(Args), Args&&... args) {
|
|
||||||
lua_createtable(L, narr, nrec);
|
|
||||||
table result(L);
|
|
||||||
result.set(std::forward<Args>(args)...);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
global_table global() const {
|
global_table global() const {
|
||||||
return globals;
|
return globals;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class table_core : public reference {
|
||||||
template<typename... Ret, std::size_t... I, typename Keys>
|
template<typename... Ret, std::size_t... I, typename Keys>
|
||||||
auto tuple_get( types<Ret...>, std::index_sequence<I...>, Keys&& keys ) const
|
auto tuple_get( types<Ret...>, std::index_sequence<I...>, Keys&& keys ) const
|
||||||
-> decltype(stack::pop<std::tuple<Ret...>>(nullptr)){
|
-> decltype(stack::pop<std::tuple<Ret...>>(nullptr)){
|
||||||
auto pp = stack::push_popper<is_global<decltype(std::get<I>(keys))...>::value>(*this);
|
auto pp = stack::push_pop<is_global<decltype(std::get<I>(keys))...>::value>(*this);
|
||||||
int tableindex = lua_gettop(lua_state());
|
int tableindex = lua_gettop(lua_state());
|
||||||
void(detail::swallow{ ( stack::get_field<top_level>(lua_state(), std::get<I>(keys), tableindex), 0)... });
|
void(detail::swallow{ ( stack::get_field<top_level>(lua_state(), std::get<I>(keys), tableindex), 0)... });
|
||||||
return stack::pop<std::tuple<Ret...>>( lua_state() );
|
return stack::pop<std::tuple<Ret...>>( lua_state() );
|
||||||
|
@ -47,14 +47,14 @@ class table_core : public reference {
|
||||||
|
|
||||||
template<typename Ret, std::size_t I, typename Keys>
|
template<typename Ret, std::size_t I, typename Keys>
|
||||||
decltype(auto) tuple_get( types<Ret>, std::index_sequence<I>, Keys&& keys ) const {
|
decltype(auto) tuple_get( types<Ret>, std::index_sequence<I>, Keys&& keys ) const {
|
||||||
auto pp = stack::push_popper<is_global<decltype(std::get<I>(keys))>::value>(*this);
|
auto pp = stack::push_pop<is_global<decltype(std::get<I>(keys))>::value>(*this);
|
||||||
stack::get_field<top_level>( lua_state( ), std::get<I>( keys ) );
|
stack::get_field<top_level>( lua_state( ), std::get<I>( keys ) );
|
||||||
return stack::pop<Ret>( lua_state( ) );
|
return stack::pop<Ret>( lua_state( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Pairs, std::size_t... I>
|
template<typename Pairs, std::size_t... I>
|
||||||
void tuple_set( std::index_sequence<I...>, Pairs&& pairs ) {
|
void tuple_set( std::index_sequence<I...>, Pairs&& pairs ) {
|
||||||
auto pp = stack::push_popper<is_global<decltype(std::get<I * 2>(pairs))...>::value>(*this);
|
auto pp = stack::push_pop<is_global<decltype(std::get<I * 2>(pairs))...>::value>(*this);
|
||||||
void(detail::swallow{ (stack::set_field<top_level>(lua_state(), std::get<I * 2>(pairs), std::get<I * 2 + 1>(pairs)), 0)... });
|
void(detail::swallow{ (stack::set_field<top_level>(lua_state(), std::get<I * 2>(pairs), std::get<I * 2 + 1>(pairs)), 0)... });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,14 +97,14 @@ public:
|
||||||
|
|
||||||
template <typename T, typename... Keys>
|
template <typename T, typename... Keys>
|
||||||
decltype(auto) traverse_get( Keys&&... keys ) const {
|
decltype(auto) traverse_get( Keys&&... keys ) const {
|
||||||
auto pp = stack::push_popper<is_global<Keys...>::value>(*this);
|
auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
|
||||||
struct clean { lua_State* L; clean(lua_State* L) : L(L) {} ~clean() { lua_pop(L, static_cast<int>(sizeof...(Keys))); } } c(lua_state());
|
struct clean { lua_State* L; clean(lua_State* L) : L(L) {} ~clean() { lua_pop(L, static_cast<int>(sizeof...(Keys))); } } c(lua_state());
|
||||||
return traverse_get_deep<top_level, T>(std::forward<Keys>(keys)...);
|
return traverse_get_deep<top_level, T>(std::forward<Keys>(keys)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Keys>
|
template <typename... Keys>
|
||||||
table_core& traverse_set( Keys&&... keys ) {
|
table_core& traverse_set( Keys&&... keys ) {
|
||||||
auto pp = stack::push_popper<is_global<Keys...>::value>(*this);
|
auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
|
||||||
traverse_set_deep<top_level>(std::forward<Keys>(keys)...);
|
traverse_set_deep<top_level>(std::forward<Keys>(keys)...);
|
||||||
lua_pop(lua_state(), static_cast<int>(sizeof...(Keys)-2));
|
lua_pop(lua_state(), static_cast<int>(sizeof...(Keys)-2));
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -128,7 +128,7 @@ public:
|
||||||
|
|
||||||
template<typename Fx>
|
template<typename Fx>
|
||||||
void for_each( Fx&& fx ) const {
|
void for_each( Fx&& fx ) const {
|
||||||
auto pp = stack::push_popper( *this );
|
auto pp = stack::push_pop( *this );
|
||||||
stack::push( lua_state( ), nil );
|
stack::push( lua_state( ), nil );
|
||||||
while ( lua_next( this->lua_state( ), -2 ) ) {
|
while ( lua_next( this->lua_state( ), -2 ) ) {
|
||||||
sol::object key( lua_state( ), -2 );
|
sol::object key( lua_state( ), -2 );
|
||||||
|
@ -139,7 +139,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size( ) const {
|
size_t size( ) const {
|
||||||
auto pp = stack::push_popper( *this );
|
auto pp = stack::push_pop( *this );
|
||||||
return lua_rawlen(lua_state(), -1);
|
return lua_rawlen(lua_state(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,6 +211,23 @@ private:
|
||||||
set(std::forward<Key>(key), function_pack<function_sig<Sig...>>(std::forward<Args>(args)...));
|
set(std::forward<Key>(key), function_pack<function_sig<Sig...>>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
namespace stack {
|
||||||
|
inline table create_table(lua_State* L, int narr = 0, int nrec = 0) {
|
||||||
|
lua_createtable(L, narr, nrec);
|
||||||
|
table result(L);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Key, typename Value, typename... Args>
|
||||||
|
inline table create_table(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
|
||||||
|
lua_createtable(L, narr, nrec);
|
||||||
|
table result(L);
|
||||||
|
result.set(std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // stack
|
||||||
} // sol
|
} // sol
|
||||||
|
|
||||||
#endif // SOL_TABLE_CORE_HPP
|
#endif // SOL_TABLE_CORE_HPP
|
||||||
|
|
Loading…
Reference in New Issue
Block a user