コード例 #1
0
ファイル: call_member.hpp プロジェクト: atomicstack/ctrlr
				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);
				}
コード例 #2
0
ファイル: call_function.hpp プロジェクト: radent/luabind
    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);
    }
コード例 #3
0
		inline T object_cast_impl(const Obj& obj, const Policies&)
		{
			if (obj.lua_state() == 0) 
			{
#ifndef LUABIND_NO_EXCEPTIONS
				throw cast_failed(0, typeid(T));
#else
				lua_State* L = obj.lua_state();
				cast_failed_callback_fun e = get_cast_failed_callback();
				if (e) e(L, typeid(T));

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

			LUABIND_CHECK_STACK(obj.lua_state());

			typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
			typename mpl::apply_wrap2<converter_policy,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, typeid(T));
#else
				cast_failed_callback_fun e = get_cast_failed_callback();
				if (e) e(L, 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);
		}
コード例 #4
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 mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter;

			if (obj.lua_state() == 0) return boost::optional<T>();
			LUABIND_CHECK_STACK(obj.lua_state());

			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));
		}