wrenbind17::ReturnValue

wrenbind17::ReturnValue #

Module: Wrenbind17

A return value when calling a Wren function (alias Any) More…

#include <any.hpp>

Public Functions #

Name
ReturnValue() =default
ReturnValue(const WrenType type, Handle handle)
~ReturnValue() =default
ReturnValue(const ReturnValue & other)
ReturnValue(ReturnValue && other)
ReturnValue & operator=(const ReturnValue & other)
ReturnValue & operator=(ReturnValue && other)
void swap(ReturnValue & other)
const Handle & getHandle() const
Handle & getHandle()
WrenType getType() constThe raw wren type held by this instance.
template <class T > bool is() constCheck if the value held is some specific C++ type.
bool isMap() const
bool isList() const
template <class T > T as()Returns the value.
template <class T > std::shared_ptr< T > shared()Returns the value as a shared pointer.

Detailed Description #

class wrenbind17::ReturnValue;

A return value when calling a Wren function (alias Any)

See: Any

Note: This variable can safely outlive the wrenbind17::VM class. If that happens then functions of this class will throw wrenbind17::RuntimeError exception. This holder will not try to free the Wren variable if the VM has been terminated. You don’t have to worry about the lifetime of this holder. (uses weak pointers).

This extends the lifetime of the Wren object (handle). As long as this ReturnValue instance exists the Wren object will exist.

Public Functions Documentation #

function ReturnValue #

ReturnValue() =default

function ReturnValue #

inline explicit ReturnValue(
    const WrenType type,
    Handle handle
)

function ~ReturnValue #

~ReturnValue() =default

function ReturnValue #

ReturnValue(
    const ReturnValue & other
)

function ReturnValue #

inline ReturnValue(
    ReturnValue && other
)

function operator= #

ReturnValue & operator=(
    const ReturnValue & other
)

function operator= #

inline ReturnValue & operator=(
    ReturnValue && other
)

function swap #

inline void swap(
    ReturnValue & other
)

function getHandle #

inline const Handle & getHandle() const

Returns the handle that this instance owns

function getHandle #

inline Handle & getHandle()

Returns the handle that this instance owns

function getType #

inline WrenType getType() const

The raw wren type held by this instance.

function is #

template <class T >
inline bool is() const

Check if the value held is some specific C++ type.

Note: If the value held is a Wren numeric type then checking for any C++ integral or floating type will return true.

function isMap #

inline bool isMap() const

function isList #

inline bool isList() const

function as #

template <class T >
inline T as()

Returns the value.

Exceptions:

  • RuntimeError if this instance is invalid (constructed via the default constructor)
  • BadCast if the type required by specifying the template argument does not match the type held

Template Parameters:

  • T the type you want to get

See: shared()

Note: If the value held is a Wren numeric type then getting for any C++ integral or floating type will result in a cast from a double to that type.

function shared #

template <class T >
inline std::shared_ptr< T > shared()

Returns the value as a shared pointer.

Exceptions:

  • RuntimeError if this instance is invalid (constructed via the default constructor)
  • BadCast if the type required by specifying the template argument does not match the type held

Template Parameters:

  • T the type of the std::shared_ptr you want to get

See: as()

Note: Only works for custom C++ classes (foreign classes) that have been bound to the VM.


Updated on 17 October 2023 at 12:26:25 UTC