diff --git a/docs/source/api/object.rst b/docs/source/api/object.rst index a7b98c30..b168df2c 100644 --- a/docs/source/api/object.rst +++ b/docs/source/api/object.rst @@ -25,7 +25,7 @@ members template object(lua_State* L, in_place_type_t, Args&&... args); -There are 4 kinds of constructors here. One allows construction of a object from other reference types such as :doc:`sol::table` and :doc:`sol::stack_reference`. The secon 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). +There are 4 kinds of constructors here. One allows construction of a object from other reference types such as :doc:`sol::table
` and :doc:`sol::stack_reference`. The secon 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` can be found in the `any_return example`_ .. code-block:: cpp :caption: function: type conversion @@ -64,3 +64,6 @@ These allow a person to compare an ``sol::object`` against :ref:`nil`, whic } Use this to check objects. + + +.. _any_return example: https://github.com/ThePhD/sol2/blob/develop/examples/any_return.cpp \ No newline at end of file diff --git a/examples/any_return.cpp b/examples/any_return.cpp index a5aa97e6..4f613036 100644 --- a/examples/any_return.cpp +++ b/examples/any_return.cpp @@ -8,12 +8,13 @@ sol::object fancy_func(sol::object a, sol::object b, sol::this_state s) { sol::state_view lua(s); if (a.is() && b.is()) { - return sol::make_object(lua, a.as() + b.as()); + return sol::object(lua, sol::in_place, a.as() + b.as()); } else if (a.is()) { bool do_triple = a.as(); - return sol::make_object(lua, b.as() * (do_triple ? 3 : 1)); + return sol::object(lua, sol::in_place, b.as() * (do_triple ? 3 : 1)); } + // Can also use make_object return sol::make_object(lua, sol::nil); }