Пример #1
0
		inline T object_cast_impl(const Obj& obj, const Policies&)
		{
			typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
			typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter;

			obj.pushvalue();

			lua_State* L = obj.lua_state();
			detail::stack_pop p(L, 1);

#ifndef LUABIND_NO_ERROR_CHECKING

			if (converter.match(L, LUABIND_DECORATE_TYPE(T), -1) < 0)
			{
#ifndef LUABIND_NO_EXCEPTIONS
				throw cast_failed(L, LUABIND_TYPEID(T));
#else
				cast_failed_callback_fun e = detail::error_callback::get().cast;
				if (e) e(L, LUABIND_TYPEID(T));

				assert(0 && "object_cast failed. If you want to handle this error use luabind::set_error_callback()");
				std::terminate();
#endif
			}
#endif

			return converter.apply(L, LUABIND_DECORATE_TYPE(T), -1);
		}
Пример #2
0
				Ret operator[](const Policies& p)
				{
					typedef typename find_conversion_policy<0, Policies>::type converter_policy;
					typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;

					m_called = true;

					// don't count the function and self-reference
					// since those will be popped by pcall
					int top = lua_gettop(L) - 2;

					// pcall will pop the function and self reference
					// and all the parameters

					detail::push_args_from_tuple<1>::apply(L, m_args, p);
# ifdef LUABIND_CPP0x
                    if (pcall(L, std::tuple_size<Tuple>::value + 1, 1))
# else
					if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1))
# endif
					{
						assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L);
#else
						error_callback_fun e = get_error_callback();
						if (e) e(L);

						assert(0 && "the lua function threw an error and exceptions are disabled."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}

					// pops the return values from the function
					stack_pop pop(L, lua_gettop(L) - top);

					if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
					{
						assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
						throw cast_failed(L, typeid(Ret));
#else
						cast_failed_callback_fun e = get_cast_failed_callback();
						if (e) e(L, typeid(Ret));

						assert(0 && "the lua function's return value could not be converted."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}

					return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
				}
Пример #3
0
				Ret operator[](const Policies& p)
				{
					typedef typename find_conversion_policy<0, Policies>::type converter_policy;
					typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter;

					m_called = true;
					lua_State* L = m_obj->lua_state();
					detail::stack_pop popper(L, 2); // pop the return value and the self reference

					// get the function
					m_obj->pushvalue();
					lua_pushstring(L, m_member_name);
					lua_gettable(L, -2);

					// push the self-object
					m_obj->pushvalue();

					detail::push_args_from_tuple<1>::apply(L, m_args, p);
					if (lua_pcall(L, boost::tuples::length<Tuple>::value + 1, 1, 0))
					{ 
#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L);
#else
						error_callback_fun e = detail::error_callback::get().err;
						if (e) e(L);
	
						assert(0 && "the lua function threw an error and exceptions are disabled."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}

#ifndef LUABIND_NO_ERROR_CHECKING

					if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
					{
#ifndef LUABIND_NO_EXCEPTIONS
						throw cast_failed(L, LUABIND_TYPEID(Ret));
#else
						cast_failed_callback_fun e = detail::error_callback::get().cast;
						if (e) e(L, LUABIND_TYPEID(Ret));

						assert(0 && "the lua function's return value could not be converted."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}
#endif
					return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
				}
Пример #4
0
int compute_score_aux(
    lua_State*L, int index, Idx, Iter, End end, Policies const& policies)
{
    typedef typename Iter::type arg_type;
    typedef typename find_conversion_policy<Idx::value, Policies>::type
        conversion_policy;
    typedef typename mpl::apply_wrap2<
        conversion_policy, arg_type, lua_to_cpp>::type converter;

    int score = converter::match(L, LUABIND_DECORATE_TYPE(arg_type), index);

    if (score < 0)
        return score;

    if (conversion_policy::has_arg)
        ++index;

    int next = compute_score_aux(
        L
      , index
      , typename mpl::next<Idx>::type()
      , typename mpl::next<Iter>::type()
      , end
      , policies
    );

    if (next < 0)
        return next;

    return score + next;
}
		int operator()(lua_State* L, int pointer_offset, D T::*member)
		{
			int nargs = lua_gettop(L);

			// parameters on the lua stack:
			// 1. object_rep
			// 2. key (property name)
			// 3. value
			object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1));
			class_rep* crep = obj->crep();

			void* raw_ptr;

			if (crep->has_holder())
				raw_ptr = crep->extractor()(obj->ptr());
			else
				raw_ptr = obj->ptr();

			T* ptr =  reinterpret_cast<T*>(static_cast<char*>(raw_ptr) + pointer_offset);

			typedef typename find_conversion_policy<1,Policies>::type converter_policy;
			typename mpl::apply_wrap2<converter_policy,D,lua_to_cpp>::type converter;
			ptr->*member = converter.apply(L, LUABIND_DECORATE_TYPE(D), 3);

			int nret = lua_gettop(L) - nargs;

			const int indices[] = { 1, nargs + nret, 3 };

			policy_list_postcall<Policies>::apply(L, indices);

			return nret;
		}
Пример #6
0
    Ret operator[](const Policies& p)
    {
        typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
        typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;

        m_called = true;
        lua_State* L = m_state;

        int top = lua_gettop(L);

        detail::push_args_from_tuple<1>::apply(L, m_args, p);
        if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
        {
            assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
            throw error(L);
#else
            error_callback_fun e = get_error_callback();
            if (e) e(L);

            assert(0 && "the lua function threw an error and exceptions are disabled."
                   " If you want to handle the error you can use luabind::set_error_callback()");
            std::terminate();
#endif
        }

        // pops the return values from the function call
        stack_pop pop(L, lua_gettop(L) - top + m_params);

        if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
        {
#ifndef LUABIND_NO_EXCEPTIONS
            throw cast_failed(L, typeid(Ret));
#else
            cast_failed_callback_fun e = get_cast_failed_callback();
            if (e) e(L, typeid(Ret));

            assert(0 && "the lua function's return value could not be converted."
                   " If you want to handle the error you can use luabind::set_error_callback()");
            std::terminate();

#endif
        }

        return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
    }
Пример #7
0
	inline void get_member_signature_impl(T(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, string_class& s)
	{
		s += "(";
#if BOOST_PP_ITERATION() > 0
		s += name_of_type(LUABIND_DECORATE_TYPE(A0), L, 0L);
		BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME, _)
#endif
		s += ")";
	}
Пример #8
0
		boost::optional<T> object_cast_nothrow_impl(const Obj& obj, const Policies&)
		{
			typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
			typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter;

			obj.pushvalue();

			lua_State* L = obj.lua_state();
			detail::stack_pop p(L, 1);

#ifndef LUABIND_NO_ERROR_CHECKING

			if (converter.match(L, LUABIND_DECORATE_TYPE(T), -1) < 0)
				return boost::optional<T>();
#endif

			return boost::optional<T>(converter.apply(L, LUABIND_DECORATE_TYPE(T), -1));
		}
Пример #9
0
	inline void get_free_function_signature_impl(T(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, std::string& s)
	{
		(void)f;
		s += "(";
#if BOOST_PP_ITERATION() > 0
		s += name_of_type(LUABIND_DECORATE_TYPE(A0), L, 0L);
		BOOST_PP_REPEAT(BOOST_PP_DEC(BOOST_PP_ITERATION()), LUABIND_ADD_LUA_TYPE_NAME, _)
#endif
		s += ")";
	}
Пример #10
0
    int operator()(lua_State* L, int pointer_offset, D T::*member)
    {
        int nargs = lua_gettop(L);

        // parameters on the lua stack:
        // 1. object_rep
        // 2. key (property name)
        // 3. value
        object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1));
        T* ptr =  reinterpret_cast<T*>(static_cast<char*>(obj->ptr()) + pointer_offset);

        typedef typename find_conversion_policy<1,Policies>::type converter_policy;
        typename converter_policy::template generate_converter<D,lua_to_cpp>::type converter;
        ptr->*member = converter.apply(L, LUABIND_DECORATE_TYPE(D), 3);

        int nret = lua_gettop(L) - nargs;

        const int indices[] = { 1, nargs + nret, 3 };

        policy_list_postcall<Policies>::apply(L, indices);

        return nret;
    }
Пример #11
0
	string_class name_of_type(by_const_pointer<T>, lua_State* L, int) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + "*"; };
Пример #12
0
	string_class name_of_type(by_const_reference<T>, lua_State* L, int) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + "&"; };
Пример #13
0
		static void apply(lua_State* L, string_class& s)
		{
			s += "(";
			s += name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L);
			s += ")";
		}
Пример #14
0
				Ret operator[](const Policies& p)
				{
					typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
					typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter;

					m_called = true;
					lua_State* L = m_func->lua_state();
#ifndef LUABIND_NO_ERROR_CHECKING
					if (L == 0)
					{
	#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L); 
	#else
						error_callback_fun e = get_error_callback();
						if (e) e(L);
	
						/*assert(0 && "tried to call uninitialized functor object."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
	#endif
					}
#endif

					detail::stack_pop popper(L, 1); // pop the return value

					// get the function
					m_func->pushvalue();

					detail::push_args_from_tuple<1>::apply(L, m_args, p);
					if (pcall(L, boost::tuples::length<Tuple>::value, 1))
					{ 
#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L);
#else
						error_callback_fun e = get_error_callback();
						if (e) e(L);
	
						/*assert(0 && "the lua function threw an error and exceptions are disabled."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
#endif
					}

#ifndef LUABIND_NO_ERROR_CHECKING

					if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
					{
#ifndef LUABIND_NO_EXCEPTIONS
						throw cast_failed(L, LUABIND_TYPEID(Ret));
#else
						cast_failed_callback_fun e = get_cast_failed_callback();
						if (e) e(L, LUABIND_TYPEID(Ret));

						/*assert(0 && "the lua function's return value could not be converted."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
#endif
					}
#endif
					return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
				}
Пример #15
0
	std::string name_of_type(by_pointer<T>, lua_State* L, int) { return name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + "*"; };
Пример #16
0
int
# ifdef LUABIND_INVOKE_MEMBER
invoke_member
# else
invoke_normal
# endif
(
    lua_State* L, F const& f, Signature, Policies const&, mpl::long_<N>
# ifdef LUABIND_INVOKE_VOID
  , mpl::true_
# else
  , mpl::false_
# endif
)
{
    typedef typename mpl::begin<Signature>::type first;
# ifndef LUABIND_INVOKE_VOID
    typedef typename mpl::deref<first>::type result_type;
    typedef typename find_conversion_policy<0, Policies>::type result_policy;
    typename mpl::apply_wrap2<
        result_policy, result_type, cpp_to_lua>::type result_converter;
# endif

# if N > 0
#  define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_DECLARE_CONVERTER(n)
#  define BOOST_PP_LOCAL_LIMITS (0,N-1)
#  include BOOST_PP_LOCAL_ITERATE()
# endif

    int const arguments = lua_gettop(L);

# ifndef LUABIND_INVOKE_VOID
    result_converter.apply(
        L,
# endif
# ifdef LUABIND_INVOKE_MEMBER
        (c0.apply(L, LUABIND_DECORATE_TYPE(a0), index0).*f)(
            BOOST_PP_ENUM(BOOST_PP_DEC(N), LUABIND_INVOKE_ARG, BOOST_PP_INC)
        )
# else
#  define LUABIND_INVOKE_IDENTITY(x) x
        f(
            BOOST_PP_ENUM(N, LUABIND_INVOKE_ARG, LUABIND_INVOKE_IDENTITY)
        )
#  undef LUABIND_INVOKE_IDENTITY
# endif
# ifndef LUABIND_INVOKE_VOID
    )
# endif
    ;

# if N > 0
#  define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_CONVERTER_POSTCALL(n)
#  define BOOST_PP_LOCAL_LIMITS (0,N-1)
#  include BOOST_PP_LOCAL_ITERATE()
# endif

    int const results = lua_gettop(L) - arguments;

    int const indices[] = {
        arguments + results BOOST_PP_ENUM_TRAILING_PARAMS(N, index)
    };

    policy_list_postcall<Policies>::apply(L, indices);

    return maybe_yield(L, results, (Policies*)0);
}
		static int apply(lua_State* L, int index)
		{
			typedef typename find_conversion_policy<1, Policies>::type converter_policy;
			typedef typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter;
			return converter::match(L, LUABIND_DECORATE_TYPE(T), index);
		}
Пример #18
0
	std::string name_of_type(by_const_pointer<T>, lua_State* L) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T), L) + "*"; };
Пример #19
0
	std::string name_of_type(by_const_reference<T>, lua_State* L) { return "const " + name_of_type(LUABIND_DECORATE_TYPE(T), L) + "&"; };
Пример #20
0
	inline string_class name_of_type(by_value<luabind::functor<T> >, lua_State* L, long) { return "function<" + name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + ">"; }
Пример #21
0
		inline static void apply(string_class& s, lua_State* L, bool first)
		{
			if (!first) s += ", ";
			s += name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L);
		}
Пример #22
0
	std::string name_of_type(by_reference<T>, lua_State* L, int) { return name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + "&"; };