// Copyright satoren // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #pragma once #include "kaguya/detail/lua_function_def.hpp" #include "kaguya/detail/lua_table_def.hpp" namespace kaguya { class LuaRef; class LuaTable; template class TableKeyReferenceProxy; class MemberFunctionBinder; namespace detail { template class LuaVariantImpl : public LuaTableImpl, public LuaTableOrUserDataImpl, public detail::LuaFunctionImpl, public detail::LuaThreadImpl, public LuaBasicTypeFunctions { private: lua_State *state_() const { return static_cast(this)->state(); } int pushStackIndex_(lua_State *state) const { return static_cast(this)->pushStackIndex(state); } public: using LuaBasicTypeFunctions::type; using LuaBasicTypeFunctions::typeName; /// @brief deprecated, use isType instead. template bool typeTest() const { return isType(); } /// @brief deprecated, use isConvertible instead. template bool weakTypeTest() const { return isConvertible(); } /// @brief is type test template bool isType() const { lua_State *state = state_(); util::ScopedSavedStack save(state); return lua_type_traits::strictCheckType(state, pushStackIndex_(state)); } template bool isConvertible() const { lua_State *state = state_(); util::ScopedSavedStack save(state); return lua_type_traits::checkType(state, pushStackIndex_(state)); } template typename lua_type_traits::get_type get() const { lua_State *state = state_(); util::ScopedSavedStack save(state); return lua_type_traits::get(state, state ? pushStackIndex_(state) : 0); } template typename lua_type_traits::get_type value_or(U v) const { lua_State *state = state_(); util::ScopedSavedStack save(state); return lua_type_traits >::get( state, state ? pushStackIndex_(state) : 0) .value_or(v); } // deprecated. use get >() instead; template typename lua_type_traits::get_type get(bool &was_valid, bool allow_convertible = true) const { lua_State *state = state_(); util::ScopedSavedStack save(state); int stackindex = pushStackIndex_(state); if (allow_convertible) { was_valid = lua_type_traits::checkType(state, stackindex); } else { was_valid = lua_type_traits::strictCheckType(state, stackindex); } if (was_valid) { return lua_type_traits::get(state, stackindex); } else { return T(); } } template operator T() const { return get(); } #if KAGUYA_USE_CPP11 template FunctionResults operator()(Args &&... args); #else inline FunctionResults operator()(); #define KAGUYA_OP_FN_DEF(N) \ template \ inline FunctionResults operator()(KAGUYA_PP_ARG_CR_DEF_REPEAT(N)); KAGUYA_PP_REPEAT_DEF(KAGUYA_FUNCTION_MAX_ARGS, KAGUYA_OP_FN_DEF) #undef KAGUYA_OP_FN_DEF #endif }; } }