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 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); if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1)) { 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); #ifndef LUABIND_NO_ERROR_CHECKING if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0) { assert(lua_gettop(L) == top + 1); #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); }
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); }
class_rep* get_class_rep(lua_State* L, void(*)(T*) = 0) { if (class_cache<T>::state != L) { class_cache<T>::state = L; class_registry* registry = class_registry::get_registry(L); class_cache<T>::class_ = registry->find_class(LUABIND_TYPEID(T)); } return class_cache<T>::class_; }
string_class name_of_type(by_value<T>, lua_State* L, int) { return luabind::detail::get_class_name(L, LUABIND_TYPEID(T)); };
class_rep* get_class_rep(lua_State* L, void(*)(T*) = 0) { class_registry* registry = class_registry::get_registry(L); return registry->find_class(LUABIND_TYPEID(T)); }
static void get(lua_State* L) { lua_pushstring(L, get_class_name(L, LUABIND_TYPEID(T)).c_str()); }
std::string name_of_type(by_value<T>, lua_State* L) { return get_class_name(L, LUABIND_TYPEID(T)); };
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); }
static LUABIND_TYPE_INFO apply() { return LUABIND_TYPEID(HeldType); }