⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 policy.hpp.svn-base

📁 本人找过多个在linux下c++的lua5.1封装库,但很少.luabind已经release的版本只支持lua5.0.这个版本是我从其cvs(svc)上取出的并支持最新的lua5.1.强烈推荐.
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
			void* obj = lua_newuserdata(L, sizeof(object_rep));			assert(obj && "internal error, please report");			new(obj) object_rep(const_cast<T*>(ptr), crep, object_rep::constant, 0);			// set the meta table			detail::getref(L, crep->metatable_ref());			lua_setmetatable(L, -2);		}	};	template<>	struct const_ref_converter<lua_to_cpp>	{		typedef boost::mpl::bool_<false> is_value_converter;		typedef const_ref_converter type;		// TODO: align!		char target[32];		void (*destructor)(void*);		const_ref_converter(): destructor(0) {}		template<class T>		typename make_const_reference<T>::type apply(lua_State* L, by_const_reference<T>, int index)		{			object_rep* obj = 0;			class_rep const * crep = 0;			// special case if we get nil in, try to convert the holder type			if (lua_isnil(L, index))			{				crep = get_class_rep<T>(L);				assert(crep);			}			else			{				obj = static_cast<object_rep*>(lua_touserdata(L, index));				assert((obj != 0) && "internal error, please report"); // internal error				crep = obj->crep();			}			assert(crep);			T* ptr = reinterpret_cast<T*>(crep->convert_to(LUABIND_TYPEID(T), obj, target));			// if the pointer returned points into the converter storage,			// we need to destruct it once the converter destructs			if ((void*)ptr == (void*)target) destructor = detail::destruct_only_s<T>::apply;			assert(!destructor || sizeof(T) <= 32);			return *ptr;		}		template<class T>		static int match(lua_State* L, by_const_reference<T>, int index)		{			// special case if we get nil in, try to match the holder type			if (lua_isnil(L, index))			{				class_rep* crep = get_class_rep<T>(L);				if (crep == 0) return -1;				if ((LUABIND_TYPE_INFO_EQUAL(crep->holder_type(), LUABIND_TYPEID(T))))					return 0;				if ((LUABIND_TYPE_INFO_EQUAL(crep->const_holder_type(), LUABIND_TYPEID(T))))					return 0;				return -1;			}			object_rep* obj = is_class_object(L, index);			if (obj == 0) return -1; // if the type is not one of our own registered types, classify it as a non-match			if ((LUABIND_TYPE_INFO_EQUAL(obj->crep()->holder_type(), LUABIND_TYPEID(T))))				return (obj->flags() & object_rep::constant)?-1:0;			if ((LUABIND_TYPE_INFO_EQUAL(obj->crep()->const_holder_type(), LUABIND_TYPEID(T))))				return (obj->flags() & object_rep::constant)?0:1;            bool const_ = obj->flags() & object_rep::constant;			int d;			int points = implicit_cast(obj->crep(), LUABIND_TYPEID(T), d);			return points == -1 ? -1 : points + !const_;		}		~const_ref_converter()		{			if (destructor) destructor(target);		}		template<class T>		void converter_postcall(lua_State* L, by_const_reference<T>, int index) 		{		}	};	// ****** enum converter ********	template<class Direction = cpp_to_lua>	struct enum_converter	{		typedef boost::mpl::bool_<false> is_value_converter;		typedef enum_converter type;				void apply(lua_State* L, int val)		{			lua_pushnumber(L, val);		}	};	template<>	struct enum_converter<lua_to_cpp>	{		typedef boost::mpl::bool_<false> is_value_converter;		typedef enum_converter type;				template<class T>		T apply(lua_State* L, by_value<T>, int index)		{			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>	{		typedef functor_converter type;				template<class T>		functor<T> apply(lua_State* L, by_const_reference<functor<T> >, int index)		{			if (lua_isnil(L, index))				return functor<T>();			lua_pushvalue(L, index);			detail::lua_reference ref;			ref.set(L);			return functor<T>(L, ref);		}		template<class T>		functor<T> apply(lua_State* L, by_value<functor<T> >, int index)		{			if (lua_isnil(L, index))				return functor<T>();			lua_pushvalue(L, index);			detail::lua_reference ref;			ref.set(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) || lua_isnil(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) || lua_isnil(L, index)) return 0; else return -1;		}		template<class T>		void converter_postcall(lua_State*, T, int) {}	};*/	template<class Direction>	struct value_wrapper_converter;	template<>	struct value_wrapper_converter<lua_to_cpp>	{		typedef boost::mpl::bool_<false> is_value_converter;		typedef value_wrapper_converter type;		template<class T>		T apply(lua_State* L, by_const_reference<T>, int index)		{			return T(from_stack(L, index));		}		template<class T>		T apply(lua_State* L, by_value<T>, int index)		{			return apply(L, by_const_reference<T>(), index);		}		template<class T>		static int match(lua_State* L, by_const_reference<T>, int index)		{			return value_wrapper_traits<T>::check(L, index)                 ? (std::numeric_limits<int>::max)() / LUABIND_MAX_ARITY                : -1;		}		template<class T>		static int match(lua_State* L, by_value<T>, int index)		{			return match(L, by_const_reference<T>(), index);		}		void converter_postcall(...) {}	};	template<>	struct value_wrapper_converter<cpp_to_lua>	{		typedef boost::mpl::bool_<false> is_value_converter;		typedef value_wrapper_converter type;    	template<class T>        void apply(lua_State* interpreter, T const& value_wrapper)		{			value_wrapper_traits<T>::unwrap(interpreter, value_wrapper);        }    };// *********** default_policy *****************	using boost::mpl::eval_if;	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, class Direction>		struct apply		  : eval_if<				is_user_defined<T>			  , user_defined_converter<Direction>			  , eval_if<    				is_value_wrapper_arg<T>				  , value_wrapper_converter<Direction>				  , eval_if<						is_primitive<T>					  , primitive_converter<Direction>					  , eval_if<//							is_lua_functor<T>//						  , functor_converter<Direction>//						  , eval_if<								boost::is_enum<T>							  , enum_converter<Direction>							  , eval_if<									is_nonconst_pointer<T>								  , pointer_converter<Direction>								  , eval_if<										is_const_pointer<T>									  , const_pointer_converter<Direction>									  , eval_if<											is_nonconst_reference<T>										  , ref_converter<Direction>										  , eval_if<												is_const_reference<T>											  , const_ref_converter<Direction>											  , value_converter<Direction>											>										>									>								>							>//						>					>				>		    >		{		};	};// ============== 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&) {}	};// ==================================================// ************** 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) {}	};}} // namespace luabind::detailnamespace luabind { namespace{#if defined(__BORLANDC__) || (BOOST_VERSION >= 103400 && defined(__GNUC__))  static inline boost::arg<0> return_value()  {	  return boost::arg<0>();  }  static inline boost::arg<0> result()  {	  return boost::arg<0>();  }# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N>(*)()#elif defined(BOOST_MSVC) || defined(__MWERKS__)  static boost::arg<0> return_value;  static boost::arg<0> result;# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N>#else  boost::arg<0> return_value;  boost::arg<0> result;# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N>#endif}}#endif // LUABIND_POLICY_HPP_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -