diff options
author | Andy <drumsetmonkey@gmail.com> | 2019-08-29 13:07:45 -0400 |
---|---|---|
committer | Andy <drumsetmonkey@gmail.com> | 2019-08-29 13:07:45 -0400 |
commit | 4ac4b280abf2ffa28caa5a532353115a3033444f (patch) | |
tree | 2a13d658bb454360b2faf401244bb0321d3460d4 /lib/sol2/docs/source/api/object.rst | |
parent | e9758416b18b27a65337c28d9641afc0ee89b34b (diff) | |
parent | 7a46fa2dd3dad3f038bf8e7339bc67abca428ae6 (diff) |
Started creating scripting library/namespace and added sol2 for interfacing
Diffstat (limited to 'lib/sol2/docs/source/api/object.rst')
-rw-r--r-- | lib/sol2/docs/source/api/object.rst | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/sol2/docs/source/api/object.rst b/lib/sol2/docs/source/api/object.rst new file mode 100644 index 0000000..8f3765d --- /dev/null +++ b/lib/sol2/docs/source/api/object.rst @@ -0,0 +1,68 @@ +object +====== +*general-purpose safety reference to an existing object* + + +.. code-block:: cpp + + class object : reference; + + +``object``'s goal is to allow someone to pass around the most generic form of a reference to something in Lua (or propogate a ``nil``). It is the logical extension of :doc:`sol::reference<reference>`, and is used in :ref:`sol::table's iterators<table-iterators>`. + + +members +------- + +.. code-block:: cpp + :caption: overloaded constructor: object + :name: overloaded-object-constructor + + template <typename T> + object(T&&); + object(lua_State* L, int index = -1); + template <typename T, typename... Args> + object(lua_State* L, in_place_t, T&& arg, Args&&... args); + template <typename T, typename... Args> + object(lua_State* L, in_place_type_t<T>, Args&&... args); + +There are 4 kinds of constructors here. One allows construction of an object from other reference types such as :doc:`sol::table<table>` and :doc:`sol::stack_reference<stack_reference>`. The second creates an object which references the specific element at the given index in the specified ``lua_State*``. The more advanced ``in_place...`` constructors create a single object by pushing the specified type ``T`` onto the stack and then setting it as the object. It gets popped from the stack afterwards (unless this is an instance of ``sol::stack_object``, in which case it is left on the stack). An example of using this and :doc:`sol::make_object<make_reference>` can be found in the `any_return example`_. + +.. code-block:: cpp + :caption: function: type conversion + + template<typename T> + decltype(auto) as() const; + +Performs a cast of the item this reference refers to into the type ``T`` and returns it. It obeys the same rules as :ref:`sol::stack::get\<T><stack-get>`. + +.. code-block:: cpp + :caption: function: type check + + template<typename T> + bool is() const; + +Performs a type check using the :ref:`sol::stack::check<stack-check>` api, after checking if the internally stored reference is valid. + + +non-members +----------- + +.. code-block:: cpp + :caption: functions: nil comparators + + bool operator==(const object& lhs, const nil_t&); + bool operator==(const nil_t&, const object& rhs); + bool operator!=(const object& lhs, const nil_t&); + bool operator!=(const nil_t&, const object& rhs); + +These allow a person to compare an ``sol::object`` against :ref:`nil<nil>`, which essentially checks if an object references a non-nil value, like so: + +.. code-block:: cpp + + if (myobj == sol::lua_nil) { + // doesn't have anything... + } + + +.. _any_return example: https://github.com/ThePhD/sol2/blob/develop/examples/source/any_return.cpp |