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