Ensures value semantics and proper destructor calls.

Fixes for tabs/spaces
This commit is contained in:
ThePhD 2016-01-28 19:57:02 -05:00
parent f389c7fe36
commit f21f9c9959
7 changed files with 283 additions and 252 deletions

View File

@ -66,7 +66,7 @@ public:
o.L = nullptr;
o.index = 0;
o.returncount = 0;
o.popcount = 0;
o.popcount = 0;
o.error = call_error::runtime;
}
function_result& operator=(function_result&& o) {
@ -80,7 +80,7 @@ public:
o.L = nullptr;
o.index = 0;
o.returncount = 0;
o.popcount = 0;
o.popcount = 0;
o.error = call_error::runtime;
return *this;
}
@ -111,91 +111,91 @@ public:
class fast_function : public reference {
private:
void luacall( std::ptrdiff_t argcount, std::ptrdiff_t resultcount ) const {
lua_callk( lua_state( ), static_cast<int>( argcount ), static_cast<int>( resultcount ), 0, nullptr );
}
void luacall( std::ptrdiff_t argcount, std::ptrdiff_t resultcount ) const {
lua_callk( lua_state( ), static_cast<int>( argcount ), static_cast<int>( resultcount ), 0, nullptr );
}
template<std::size_t... I, typename... Ret>
std::tuple<Ret...> invoke( indices<I...>, types<Ret...>, std::ptrdiff_t n ) const {
luacall( n, sizeof...( Ret ), h );
int nreturns = static_cast<int>( sizeof...( Ret ) );
int stacksize = lua_gettop( lua_state( ) );
int firstreturn = std::max( 0, stacksize - nreturns ) + 1;
auto r = std::make_tuple( stack::get<Ret>( lua_state( ), firstreturn + I )... );
lua_pop( lua_state( ), nreturns );
return r;
}
template<std::size_t... I, typename... Ret>
std::tuple<Ret...> invoke( indices<I...>, types<Ret...>, std::ptrdiff_t n ) const {
luacall( n, sizeof...( Ret ), h );
int nreturns = static_cast<int>( sizeof...( Ret ) );
int stacksize = lua_gettop( lua_state( ) );
int firstreturn = std::max( 0, stacksize - nreturns ) + 1;
auto r = std::make_tuple( stack::get<Ret>( lua_state( ), firstreturn + I )... );
lua_pop( lua_state( ), nreturns );
return r;
}
template<std::size_t I, typename Ret>
Ret invoke( indices<I>, types<Ret>, std::ptrdiff_t n ) const {
luacall( n, 1 );
return stack::pop<Ret>( lua_state( ) );
}
template<std::size_t I, typename Ret>
Ret invoke( indices<I>, types<Ret>, std::ptrdiff_t n ) const {
luacall( n, 1 );
return stack::pop<Ret>( lua_state( ) );
}
template <std::size_t I>
void invoke( indices<I>, types<void>, std::ptrdiff_t n ) const {
luacall( n, 0 );
}
template <std::size_t I>
void invoke( indices<I>, types<void>, std::ptrdiff_t n ) const {
luacall( n, 0 );
}
function_result invoke( indices<>, types<>, std::ptrdiff_t n ) const {
int stacksize = lua_gettop( lua_state( ) );
int firstreturn = std::max( 0, stacksize - static_cast<int>( n ) - 1 );
int poststacksize = 0;
int returncount = 0;
try {
luacall( n, LUA_MULTRET );
poststacksize = lua_gettop( lua_state( ) );
returncount = poststacksize - firstreturn;
}
// Handle C++ errors thrown from C++ functions bound inside of lua
catch ( const std::exception& error ) {
stack::push( lua_state( ), error.what( ) );
return function_result( lua_state( ), firstreturn, 0, 1, call_error::runtime );
}
catch ( ... ) {
throw;
}
return function_result( lua_state( ), firstreturn, returncount, returncount, call_error::ok );
}
function_result invoke( indices<>, types<>, std::ptrdiff_t n ) const {
int stacksize = lua_gettop( lua_state( ) );
int firstreturn = std::max( 0, stacksize - static_cast<int>( n ) - 1 );
int poststacksize = 0;
int returncount = 0;
try {
luacall( n, LUA_MULTRET );
poststacksize = lua_gettop( lua_state( ) );
returncount = poststacksize - firstreturn;
}
// Handle C++ errors thrown from C++ functions bound inside of lua
catch ( const std::exception& error ) {
stack::push( lua_state( ), error.what( ) );
return function_result( lua_state( ), firstreturn, 0, 1, call_error::runtime );
}
catch ( ... ) {
throw;
}
return function_result( lua_state( ), firstreturn, returncount, returncount, call_error::ok );
}
public:
fast_function( ) = default;
fast_function( lua_State* L, int index = -1 ) : reference( L, index ) {
type_assert( L, index, type::function );
}
fast_function( const fast_function& ) = default;
fast_function& operator=( const fast_function& ) = default;
fast_function( fast_function&& ) = default;
fast_function& operator=( fast_function&& ) = default;
fast_function( ) = default;
fast_function( lua_State* L, int index = -1 ) : reference( L, index ) {
type_assert( L, index, type::function );
}
fast_function( const fast_function& ) = default;
fast_function& operator=( const fast_function& ) = default;
fast_function( fast_function&& ) = default;
fast_function& operator=( fast_function&& ) = default;
template<typename... Args>
function_result operator()( Args&&... args ) const {
return call<>( std::forward<Args>( args )... );
}
template<typename... Args>
function_result operator()( Args&&... args ) const {
return call<>( std::forward<Args>( args )... );
}
template<typename... Ret, typename... Args>
auto operator()( types<Ret...>, Args&&... args ) const
-> decltype( invoke( types<Ret...>( ), types<Ret...>( ), 0, std::declval<handler&>( ) ) ) {
return call<Ret...>( std::forward<Args>( args )... );
}
template<typename... Ret, typename... Args>
auto operator()( types<Ret...>, Args&&... args ) const
-> decltype( invoke( types<Ret...>( ), types<Ret...>( ), 0, std::declval<handler&>( ) ) ) {
return call<Ret...>( std::forward<Args>( args )... );
}
template<typename... Ret, typename... Args>
auto call( Args&&... args ) const
-> decltype( invoke( types<Ret...>( ), types<Ret...>( ), 0 ) ) {
push( );
int pushcount = stack::push_args( lua_state( ), std::forward<Args>( args )... );
auto tr = types<Ret...>( );
return invoke( tr, tr, pushcount );
}
template<typename... Ret, typename... Args>
auto call( Args&&... args ) const
-> decltype( invoke( types<Ret...>( ), types<Ret...>( ), 0 ) ) {
push( );
int pushcount = stack::push_args( lua_state( ), std::forward<Args>( args )... );
auto tr = types<Ret...>( );
return invoke( tr, tr, pushcount );
}
};
class safe_function : public reference {
private:
static reference& handler_storage() {
static sol::reference h;
return h;
}
static reference& handler_storage() {
static sol::reference h;
return h;
}
public:
static const reference& get_default_handler () {
@ -253,21 +253,21 @@ private:
bool handlerpushed = error_handler.valid();
int stacksize = lua_gettop(lua_state());
int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1);
int returncount = 0;
call_error code = call_error::ok;
int returncount = 0;
call_error code = call_error::ok;
try {
code = static_cast<call_error>(luacall(n, LUA_MULTRET, h));
int poststacksize = lua_gettop( lua_state( ) );
returncount = poststacksize - firstreturn;
}
int poststacksize = lua_gettop( lua_state( ) );
returncount = poststacksize - firstreturn;
}
// Handle C++ errors thrown from C++ functions bound inside of lua
catch (const std::exception& error) {
code = call_error::runtime;
h.stackindex = 0;
h.stackindex = 0;
stack::push(lua_state(), error.what());
return function_result( lua_state( ), firstreturn, 0, 1, call_error::runtime );
}
}
catch (...) {
throw;
}
@ -376,7 +376,7 @@ struct pusher<function_sig_t<Sigs...>> {
template<typename Fx, typename T>
static void set_reference_fx(std::false_type, lua_State* L, Fx&& fx, T&& obj) {
typedef typename std::remove_pointer<Decay<Fx>>::type clean_fx;
std::unique_ptr<base_function> sptr(new member_function<clean_fx, T>(std::forward<T>(obj), std::forward<Fx>(fx)));
std::unique_ptr<base_function> sptr(new member_function<clean_fx, Unqualified<T>>(std::forward<T>(obj), std::forward<Fx>(fx)));
return set_fx<Fx>(L, std::move(sptr));
}
@ -411,7 +411,7 @@ struct pusher<function_sig_t<Sigs...>> {
template<typename Fx>
static void set_fx(lua_State* L, std::unique_ptr<base_function> luafunc) {
auto&& metakey = usertype_traits<Unqualified<Fx>>::metatable;
const auto& metakey = usertype_traits<Unqualified<Fx>>::metatable;
const char* metatablename = std::addressof(metakey[0]);
base_function* target = luafunc.release();
void* userdata = reinterpret_cast<void*>(target);

View File

@ -168,7 +168,7 @@ struct static_function {
template<typename... Ret, typename... Args>
static int typed_call(types<Ret...>, types<Args...> ta, function_type* fx, lua_State* L) {
typedef typename return_type<Ret...>::type return_type;
typedef decltype(stack::call(L, 0, types<return_type>(), ta, fx)) ret_t;
typedef decltype(stack::call(L, 0, types<return_type>(), ta, fx)) ret_t;
ret_t r = stack::call(L, 0, types<return_type>(), ta, fx);
int nargs = static_cast<int>(sizeof...(Args));
lua_pop(L, nargs);
@ -373,7 +373,8 @@ struct member_function : public base_function {
template<typename... Args>
return_type operator()(Args&&... args) {
return (member.*invocation)(std::forward<Args>(args)...);
auto& mem = unwrapper(unref(member));
return (mem.*invocation)(std::forward<Args>(args)...);
}
} fx;

View File

@ -47,7 +47,7 @@ public:
template<typename... Args>
proxy& set_function(Args&&... args) {
tbl.set_function(key, std::forward<Args>(args)...);
return *this;
return *this;
}
template<typename U, EnableIf<Function<Unqualified<U>>> = 0>
@ -73,17 +73,17 @@ public:
template<typename T, EnableIf<Not<is_string_constructible<T>>, is_lua_primitive<T>> = 0>
operator T ( ) const {
return get<T>( );
return get<T>( );
}
template<typename T, EnableIf<Not<is_string_constructible<T>>, Not<is_lua_primitive<T>>> = 0>
operator T& ( ) const {
return get<T&>( );
return get<T&>( );
}
template <typename K>
decltype(auto) operator[](K&& key) const {
return get<table>()[std::forward<K>(key)];
return get<table>()[std::forward<K>(key)];
}
template<typename... Ret, typename... Args>

View File

@ -25,7 +25,7 @@
#include "table_core.hpp"
namespace sol {
typedef table_core<false> table;
typedef table_core<false> table;
} // sol
#endif // SOL_TABLE_HPP

View File

@ -29,195 +29,195 @@
namespace sol {
namespace detail {
struct global_overload_tag { } const global_overload;
struct global_overload_tag { } const global_overload;
} // detail
template <bool top_level>
class table_core : public reference {
friend class state;
template<typename T, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
lua_getglobal( lua_state( ), &key[ 0 ] );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
return result;
}
friend class state;
template<typename T, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
lua_getglobal( lua_state( ), &key[ 0 ] );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
return result;
}
template<typename T, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
lua_gettable( lua_state( ), -2 );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
pop( );
return result;
}
template<typename T, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
lua_gettable( lua_state( ), -2 );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
pop( );
return result;
}
template<typename Keys, typename... Ret, std::size_t... I>
stack::get_return<Ret...> tuple_get( types<Ret...>, indices<I...>, Keys&& keys ) const {
return stack::get_return<Ret...>( single_get<Ret>( std::get<I>( keys ) )... );
}
template<typename Keys, typename... Ret, std::size_t... I>
stack::get_return<Ret...> tuple_get( types<Ret...>, indices<I...>, Keys&& keys ) const {
return stack::get_return<Ret...>( single_get<Ret>( std::get<I>( keys ) )... );
}
template<typename Keys, typename Ret, std::size_t I>
stack::get_return<Ret> tuple_get( types<Ret>, indices<I>, Keys&& keys ) const {
return single_get<Ret>( std::get<I>( keys ) );
}
template<typename Keys, typename Ret, std::size_t I>
stack::get_return<Ret> tuple_get( types<Ret>, indices<I>, Keys&& keys ) const {
return single_get<Ret>( std::get<I>( keys ) );
}
#if SOL_LUA_VERSION < 502
table_core( detail::global_overload_tag, const table_core<false>& reg ) noexcept : reference( reg.lua_state(), LUA_GLOBALSINDEX ) { }
table_core( detail::global_overload_tag, const table_core<false>& reg ) noexcept : reference( reg.lua_state(), LUA_GLOBALSINDEX ) { }
#else
table_core( detail::global_overload_tag, const table& reg ) noexcept : reference( reg.get<table>( LUA_RIDX_GLOBALS ) ) { }
table_core( detail::global_overload_tag, const table& reg ) noexcept : reference( reg.get<table>( LUA_RIDX_GLOBALS ) ) { }
#endif
public:
table_core( ) noexcept : reference( ) { }
table_core( const table_core<true>& global ) : reference( global ) { }
table_core( lua_State* L, int index = -1 ) : reference( L, index ) {
type_assert( L, index, type::table );
}
table_core( ) noexcept : reference( ) { }
table_core( const table_core<true>& global ) : reference( global ) { }
table_core( lua_State* L, int index = -1 ) : reference( L, index ) {
type_assert( L, index, type::table );
}
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... ) );
}
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... ) );
}
template<typename T, typename U>
table_core& set( T&& key, U&& value ) {
if ( top_level ) {
stack::push( lua_state( ), std::forward<U>( value ) );
lua_setglobal( lua_state( ), &key[0] );
}
else {
push( );
stack::push( lua_state( ), std::forward<T>( key ) );
stack::push( lua_state( ), std::forward<U>( value ) );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename T, typename U>
table_core& set( T&& key, U&& value ) {
if ( top_level ) {
stack::push( lua_state( ), std::forward<U>( value ) );
lua_setglobal( lua_state( ), &key[0] );
}
else {
push( );
stack::push( lua_state( ), std::forward<T>( key ) );
stack::push( lua_state( ), std::forward<U>( value ) );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename T>
SOL_DEPRECATED table_core& set_userdata( usertype<T>& user ) {
return set_usertype( user );
}
template<typename T>
SOL_DEPRECATED table_core& set_userdata( usertype<T>& user ) {
return set_usertype( user );
}
template<typename Key, typename T>
SOL_DEPRECATED table_core& set_userdata( Key&& key, usertype<T>& user ) {
return set_usertype( std::forward<Key>( key ), user );
}
template<typename Key, typename T>
SOL_DEPRECATED table_core& set_userdata( Key&& key, usertype<T>& user ) {
return set_usertype( std::forward<Key>( key ), user );
}
template<typename T>
table_core& set_usertype( usertype<T>& user ) {
return set_usertype( usertype_traits<T>::name, user );
}
template<typename T>
table_core& set_usertype( usertype<T>& user ) {
return set_usertype( usertype_traits<T>::name, user );
}
template<typename Key, typename T>
table_core& set_usertype( Key&& key, usertype<T>& user ) {
if ( top_level ) {
stack::push( lua_state( ), user );
lua_setglobal( lua_state( ), &key[ 0 ] );
pop( );
}
else {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
stack::push( lua_state( ), user );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename Key, typename T>
table_core& set_usertype( Key&& key, usertype<T>& user ) {
if ( top_level ) {
stack::push( lua_state( ), user );
lua_setglobal( lua_state( ), &key[ 0 ] );
pop( );
}
else {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
stack::push( lua_state( ), user );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename Fx>
void for_each( Fx&& fx ) const {
push( );
stack::push( lua_state( ), nil );
while ( lua_next( this->lua_state( ), -2 ) ) {
sol::object key( lua_state( ), -2 );
sol::object value( lua_state( ), -1 );
fx( key, value );
lua_pop( lua_state( ), 1 );
}
pop( );
}
template<typename Fx>
void for_each( Fx&& fx ) const {
push( );
stack::push( lua_state( ), nil );
while ( lua_next( this->lua_state( ), -2 ) ) {
sol::object key( lua_state( ), -2 );
sol::object value( lua_state( ), -1 );
fx( key, value );
lua_pop( lua_state( ), 1 );
}
pop( );
}
size_t size( ) const {
push( );
size_t result = lua_rawlen( lua_state( ), -1 );
pop( );
return result;
}
size_t size( ) const {
push( );
size_t result = lua_rawlen( lua_state( ), -1 );
pop( );
return result;
}
template<typename T>
proxy<table_core, T> operator[]( T&& key ) {
return proxy<table_core, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<table_core, T> operator[]( T&& key ) {
return proxy<table_core, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<const table_core, T> operator[]( T&& key ) const {
return proxy<const table_core, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<const table_core, T> operator[]( T&& key ) const {
return proxy<const table_core, T>( *this, std::forward<T>( key ) );
}
void pop( int n = 1 ) const noexcept {
lua_pop( lua_state( ), n );
}
void pop( int n = 1 ) const noexcept {
lua_pop( lua_state( ), n );
}
template<typename... Args, typename R, typename Key>
table_core& set_function( Key&& key, R fun_ptr( Args... ) ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename... Args, typename R, typename Key>
table_core& set_function( Key&& key, R fun_ptr( Args... ) ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename Sig, typename Key>
table_core& set_function( Key&& key, Sig* fun_ptr ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename Sig, typename Key>
table_core& set_function( Key&& key, Sig* fun_ptr ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename... Args, typename R, typename C, typename T, typename Key>
table_core& set_function( Key&& key, R( C::*mem_ptr )( Args... ), T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename... Args, typename R, typename C, typename T, typename Key>
table_core& set_function( Key&& key, R( C::*mem_ptr )( Args... ), T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename Sig, typename C, typename T, typename Key>
table_core& set_function( Key&& key, Sig C::* mem_ptr, T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename Sig, typename C, typename T, typename Key>
table_core& set_function( Key&& key, Sig C::* mem_ptr, T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename... Sig, typename Fx, typename Key>
table_core& set_function( Key&& key, Fx&& fx ) {
set_fx( types<Sig...>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
return *this;
}
template<typename... Sig, typename Fx, typename Key>
table_core& set_function( Key&& key, Fx&& fx ) {
set_fx( types<Sig...>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
return *this;
}
private:
template<typename R, typename... Args, typename Fx, typename Key, typename = typename std::result_of<Fx( Args... )>::type>
void set_fx( types<R( Args... )>, Key&& key, Fx&& fx ) {
set_resolved_function<R( Args... )>( std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename R, typename... Args, typename Fx, typename Key, typename = typename std::result_of<Fx( Args... )>::type>
void set_fx( types<R( Args... )>, Key&& key, Fx&& fx ) {
set_resolved_function<R( Args... )>( std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename Fx, typename Key>
void set_fx( types<>, Key&& key, Fx&& fx ) {
typedef Unqualified<Unwrap<Fx>> fx_t;
typedef decltype( &fx_t::operator() ) Sig;
set_fx( types<function_signature_t<Sig>>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename Fx, typename Key>
void set_fx( types<>, Key&& key, Fx&& fx ) {
typedef Unqualified<Unwrap<Fx>> fx_t;
typedef decltype( &fx_t::operator() ) Sig;
set_fx( types<function_signature_t<Sig>>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename... Sig, typename... Args, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setglobal( lua_state( ), &key[ 0 ] );
}
template<typename... Sig, typename... Args, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setglobal( lua_state( ), &key[ 0 ] );
}
template<typename... Sig, typename... Args, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
push( );
int tabletarget = lua_gettop( lua_state( ) );
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setfield( lua_state( ), tabletarget, &key[ 0 ] );
pop( );
}
template<typename... Sig, typename... Args, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
push( );
int tabletarget = lua_gettop( lua_state( ) );
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setfield( lua_state( ), tabletarget, &key[ 0 ] );
pop( );
}
};
} // sol

View File

@ -24,6 +24,7 @@
#include "tuple.hpp"
#include <type_traits>
#include <memory>
#include <functional>
namespace sol {
@ -324,6 +325,35 @@ Unwrap<Arg> unwrapper(std::reference_wrapper<Arg> arg) {
return arg.get();
}
template<typename T>
T& unref(T& item) {
return item;
}
template<typename T>
T& unref(T* item) {
return *item;
}
template<typename T>
T& unref(std::unique_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(std::shared_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(const std::unique_ptr<T>& item) {
return *item;
}
template<typename T>
T& unref(const std::shared_ptr<T>& item) {
return *item;
}
} // sol
#endif // SOL_TRAITS_HPP

View File

@ -64,11 +64,11 @@ enum class call_syntax {
};
enum class call_error : int {
ok = LUA_OK,
runtime = LUA_ERRRUN,
memory = LUA_ERRMEM,
handler = LUA_ERRERR,
gc = LUA_ERRGCMM
ok = LUA_OK,
runtime = LUA_ERRRUN,
memory = LUA_ERRMEM,
handler = LUA_ERRERR,
gc = LUA_ERRGCMM
};
enum class type : int {