Ejemplo n.º 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);
		}
Ejemplo n.º 2
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)
			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<0,Policies>::type converter_policy;
			typename converter_policy::template generate_converter<D,cpp_to_lua>::type converter;
			converter.apply(L, ptr->*member);

			int nret = lua_gettop(L) - nargs;

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

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

			return nret;
		}
Ejemplo n.º 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);
				}
Ejemplo n.º 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 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));
		}
Ejemplo n.º 5
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;
    }
Ejemplo n.º 6
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);
				}