Alien-XGBoost
view release on metacpan or search on metacpan
xgboost/dmlc-core/include/dmlc/lua.h view on Meta::CPAN
#include "./thread_local.h"
namespace dmlc {
// forward declare torch state
class LuaState;
namespace lua_stack {
template<typename T>
struct Handler;
};
/*! \brief an reference to lua object */
class LuaRef {
public:
/*! \brief construct an nil ref */
LuaRef() = default;
/*!
* \brief move constructor from another LuaRef
* \param other The other LuaRef to be moved
*/
inline LuaRef(LuaRef&& other); // NOLINT(*)
/*!
* \brief copy constructor
* \param other The other LuaRef to be copied
*/
inline LuaRef(const LuaRef& other); // NOLINT(*)
/*!
* \brief assign operator from other
* \param other The other LuaRef to be copy or moved.
* \return self
*/
inline LuaRef& operator=(LuaRef&& other);
/*!
* \brief assign operator from other
* \param other The other LuaRef to be copy or moved.
* \return self
*/
inline LuaRef& operator=(const LuaRef& other);
/*! \brief destructor */
inline ~LuaRef();
/*!
* \brief swap content with another ref
* \param other another LuaRef to be swaped.
*/
inline void swap(LuaRef& other); // NOLINT(*)
/*!
* \brief Get content out as type T.
*
* \tparam T the type to be fetched.
* \return the corresponding c type.
*/
template<typename T>
inline T Get() const;
/*!
* \brief Get user data pointer from LuaRef
*
* CAREFUL when getting userdata(e.g. pointer to Tensor's storage) from LuaRef.
* Remember they are managed by Lua, and can get deleted when all the
* LuaRef to the userdata destructs. A good practice is always use a LuaRef to keep
* the userdata alive when you need them from C++ side.
*
* \tparam T the type of pointer to be fetched.
* \return the corresponding c type.
*/
template<typename T>
inline T* GetUDataPtr() const;
/*! \return whether the value is nil */
inline bool is_nil() const;
/*!
* \brief invoke the LuaRef as function
* \param args Arguments to be passed.
* \tparam Args arguments to be passed.
* \return The first return value.
*/
template<typename... Args>
inline LuaRef operator()(Args&& ...args) const;
/*!
* \brief Get field from the lua table.
* The reference must be a table
* \param key The key to the table
* \return a new ref to the corresponding field.
*/
inline LuaRef operator[](const std::string& key) const;
/*!
* \brief Get field from the lua array
* The reference must be a array
* \param index The index to the array,
* Note: the index convention follows lua table, starts from 1
* \return a new ref to the corresponding field.
*/
inline LuaRef operator[](size_t index) const;
/*!
* \brief Set field of lua table.
* The reference must be a table
* \param key The key to the table
* \param value Lua convertable value to be setted.
* \return self.
*/
template<typename T>
inline LuaRef& SetField(const std::string& key, const T& value); // NOLINT(*)
/*!
* \brief Set LuaRef to the value on top of the stack.
* This state must be nil.
* This is API used by developer.
*
* \param s the corresponding lua state.
*/
inline void SetByPopStack_(LuaState* s);
private:
// friend with luastate
friend struct lua_stack::Handler<LuaRef>;
friend class LuaState;
friend std::ostream &operator<<(std::ostream &os, const LuaRef &r);
/*! \brief pointer to the state */
LuaState* state_{nullptr};
/*! \brief reference index */
int ref_;
};
( run in 0.807 second using v1.01-cache-2.11-cpan-df04353d9ac )