📄 policy.hpp
字号:
}
else
{
object_ptr = new T(ref);
}
new(obj_rep) object_rep(object_ptr, crep, flags, destructor);
// set the meta table
detail::getref(L, crep->metatable_ref());
lua_setmetatable(L, -2);
}
};
template<>
struct const_ref_converter<lua_to_cpp>
: private const_pointer_converter<lua_to_cpp>
{
template<class T>
typename make_const_reference<T>::type apply(lua_State* L, by_const_reference<T>, int index)
{
// std::cerr << "const_ref_converter<lua_to_cpp>\n";
return *const_pointer_converter<lua_to_cpp>::apply(L, by_const_pointer<T>(), index);
}
template<class T>
static int match(lua_State* L, by_const_reference<T>, int index)
{
return const_pointer_converter<lua_to_cpp>::match(L, by_const_pointer<T>(), index);
}
template<class T>
void converter_postcall(lua_State* L, by_const_reference<T>, int index)
{
const_pointer_converter<lua_to_cpp>::converter_postcall(L, by_const_pointer<T>(), index);
}
};
// ****** enum converter ********
template<class Direction = cpp_to_lua>
struct enum_converter;
template<>
struct enum_converter<lua_to_cpp>
{
template<class T>
T apply(lua_State* L, by_value<T>, int index)
{
// std::cerr << "enum_converter\n";
return static_cast<T>(static_cast<int>(lua_tonumber(L, index)));
}
template<class T>
static int match(lua_State* L, by_value<T>, int index)
{
if (lua_isnumber(L, index)) return 0; else return -1;
}
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
// ****** functor converter ********
template<class Direction> struct functor_converter;
template<>
struct functor_converter<lua_to_cpp>
{
template<class T>
functor<T> apply(lua_State* L, by_const_reference<functor<T> >, int index)
{
lua_pushvalue(L, index);
int ref = detail::ref(L);
return functor<T>(L, ref);
}
template<class T>
functor<T> apply(lua_State* L, by_value<functor<T> >, int index)
{
lua_pushvalue(L, index);
int ref = detail::ref(L);
return functor<T>(L, ref);
}
template<class T>
static int match(lua_State* L, by_const_reference<functor<T> >, int index)
{
if (lua_isfunction(L, index)) return 0; else return -1;
}
template<class T>
static int match(lua_State* L, by_value<functor<T> >, int index)
{
if (lua_isfunction(L, index)) return 0; else return -1;
}
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
// *********** default_policy *****************
struct default_policy : converter_policy_tag
{
BOOST_STATIC_CONSTANT(bool, has_arg = true);
template<class T>
static void precall(lua_State*, T, int) {}
// template<class T>
// static void postcall(lua_State*, T, int) {}
template<class T, class Direction>
struct generate_converter
{
typedef typename boost::mpl::if_<is_user_defined<T>
, user_defined_converter<Direction>
// , typename boost::mpl::if_<is_implicit_conversion<T>
// , implicit_converter<Direction>
, typename boost::mpl::if_<is_primitive<T>
, primitive_converter<Direction>
, typename boost::mpl::if_<is_lua_functor<T>
, functor_converter<Direction>
, typename boost::mpl::if_<boost::is_enum<T>
, enum_converter<Direction>
, typename boost::mpl::if_<is_nonconst_pointer<T>
, pointer_converter<Direction>
, typename boost::mpl::if_<is_const_pointer<T>
, const_pointer_converter<Direction>
, typename boost::mpl::if_<is_nonconst_reference<T>
, ref_converter<Direction>
, typename boost::mpl::if_<is_const_reference<T>
, const_ref_converter<Direction>
, value_converter<Direction>
>::type>::type>::type>::type>::type>::type>::type>::type type;
};
};
// ********** get policy **********
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
template<int N, class T>
struct get_policy_list_impl
{
template<class U>
struct inner
{
typedef typename U::head head;
typedef typename U::tail tail;
typedef typename boost::mpl::if_<boost::mpl::equal_to<boost::mpl::integral_c<int, head::index>, boost::mpl::integral_c<int, N> >
, policy_cons<head, typename get_policy_list_impl<N, tail>::type>
, typename get_policy_list_impl<N, tail>::type
>::type type;
};
template<>
struct inner<null_type>
{
typedef null_type type;
};
typedef typename inner<T>::type type;
};
#else
template<class List>
struct get_policy_list_impl
{
template<int N>
struct apply
{
typedef typename List::head head;
typedef typename List::tail tail;
typedef typename boost::mpl::if_<boost::mpl::equal_to<boost::mpl::integral_c<int, head::index>, boost::mpl::integral_c<int, N> >
, policy_cons<head, typename get_policy_list_impl<tail>::template apply<N>::type>
, typename get_policy_list_impl<tail>::template apply<N>::type
>::type type;
};
};
template<>
struct get_policy_list_impl<detail::null_type>
{
template<int N>
struct apply
{
typedef null_type type;
};
};
#endif
template<int N, class T>
struct get_policy_list
{
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
typedef typename get_policy_list_impl<N, T>::type type;
#else
typedef typename get_policy_list_impl<T>::template apply<N>::type type;
#endif
};
// ============== new policy system =================
template<int, class> struct find_conversion_policy;
template<bool IsConverter = false>
struct find_conversion_impl
{
template<int N, class Policies>
struct apply
{
typedef typename find_conversion_policy<N, typename Policies::tail>::type type;
};
};
template<>
struct find_conversion_impl<true>
{
template<int N, class Policies>
struct apply
{
typedef typename Policies::head head;
typedef typename Policies::tail tail;
BOOST_STATIC_CONSTANT(bool, found = (N == head::index));
typedef typename
boost::mpl::if_c<found
, head
, typename find_conversion_policy<N, tail>::type
>::type type;
};
};
template<class Policies>
struct find_conversion_impl2
{
template<int N>
struct apply
: find_conversion_impl<
boost::is_base_and_derived<conversion_policy_base, typename Policies::head>::value
>::template apply<N, Policies>
{
};
};
template<>
struct find_conversion_impl2<detail::null_type>
{
template<int N>
struct apply
{
typedef default_policy type;
};
};
template<int N, class Policies>
struct find_conversion_policy : find_conversion_impl2<Policies>::template apply<N>
{
};
template<class List>
struct policy_list_postcall
{
typedef typename List::head head;
typedef typename List::tail tail;
static void apply(lua_State* L, const index_map& i)
{
head::postcall(L, i);
policy_list_postcall<tail>::apply(L, i);
}
};
template<>
struct policy_list_postcall<detail::null_type>
{
static void apply(lua_State*, const index_map&) {}
};
/* template<int N>
struct find_conversion_policy<N, detail::null_type>
{
typedef default_policy type;
};*/
// ==================================================
// ************** precall and postcall on policy_cons *********************
template<class List>
struct policy_precall
{
typedef typename List::head head;
typedef typename List::tail tail;
static void apply(lua_State* L, int index)
{
head::precall(L, index);
policy_precall<tail>::apply(L, index);
}
};
template<>
struct policy_precall<detail::null_type>
{
static void apply(lua_State*, int) {}
};
template<class List>
struct policy_postcall
{
typedef typename List::head head;
typedef typename List::tail tail;
static void apply(lua_State* L, int index)
{
head::postcall(L, index);
policy_postcall<tail>::apply(L, index);
}
};
template<>
struct policy_postcall<detail::null_type>
{
static void apply(lua_State*, int) {}
};
/*
struct pointer_only_converter
{
template<class T>
static const T* apply(lua_State* L, type<const T*>, int index)
{
int a = index;
}
};
*/
struct only_one_converter_policy_can_be_used_per_index {};
template<class List, class T> struct assert_converter_policy_impl;
template<class List>
struct assert_converter_policy
{
template<class T>
struct apply
{
typedef typename boost::mpl::if_<boost::is_base_and_derived<converter_policy_tag, typename List::head>
, only_one_converter_policy_can_be_used_per_index
, typename assert_converter_policy_impl<typename List::tail, T>::type
>::type type;
};
};
template<>
struct assert_converter_policy<detail::null_type>
{
template<class T>
struct apply
{
typedef T type;
};
};
template<class List, class T>
struct assert_converter_policy_impl
{
typedef typename assert_converter_policy<List>::template apply<T>::type type;
};
template<class List>
struct find_converter_policy_impl
{
typedef typename List::head head;
typedef typename List::tail tail;
typedef typename boost::mpl::if_<boost::is_base_and_derived<converter_policy_tag, head>
, typename assert_converter_policy_impl<tail, head>::type
, typename find_converter_policy_impl<tail>::type
>::type type;
};
template<>
struct find_converter_policy_impl<detail::null_type>
{
typedef default_policy type;
};
}
/*
namespace converters
{
template<class T>
struct FROM
{
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
template<class U, int N>
static U convert(lua_State* L, boost::mpl::int_<N>, detail::type<U>, int index)
{
typename luabind::detail::default_policy
::generate_converter<T, detail::lua_to_cpp>::type c;
return static_cast<U>(c.apply(L,
LUABIND_DECORATE_TYPE(T), index));
}
template<class U>
static std::pair<int,int> match(lua_State* L, boost::mpl::int_<N>, detail::type<U>, int index)
{
typedef typename luabind::detail::default_policy
::generate_converter<T, detail::lua_to_cpp>::type c;
int my_match = c::match(L, LUABIND_DECORATE_TYPE(T), index);
std::pair<int,int> result = TO<N + 1, U>
::match(L, boost::mpl::int_<N + 1>(), detail::type<U>(), index);
if (my_match < result.first() && my_match != -1)
return std::make_pair(my_match, N);
else
return result;
}
};
}
*/
}
namespace luabind { namespace
{
LUABIND_ANONYMOUS_FIX boost::arg<0> return_value;
LUABIND_ANONYMOUS_FIX boost::arg<0> result;
}}
#include <luabind/detail/object_funs.hpp>
#endif // LUABIND_POLICY_HPP_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -