diff options
author | 2016-11-15 22:21:07 -0600 | |
---|---|---|
committer | 2016-11-15 22:21:07 -0600 | |
commit | a68d4239929802bca7131d4b97c2b8d149fbbcb9 (patch) | |
tree | 03a497191ccd83206e94c60aca635eb44d51c0f7 /3rdparty/sol2/docs/source/api | |
parent | 4d533249fdf28d3a473426130a82e673b1b1d5ec (diff) |
luaengine: use initializers (nw)
Diffstat (limited to '3rdparty/sol2/docs/source/api')
-rw-r--r-- | 3rdparty/sol2/docs/source/api/containers.rst | 2 | ||||
-rw-r--r-- | 3rdparty/sol2/docs/source/api/function.rst | 8 | ||||
-rw-r--r-- | 3rdparty/sol2/docs/source/api/resolve.rst | 28 |
3 files changed, 33 insertions, 5 deletions
diff --git a/3rdparty/sol2/docs/source/api/containers.rst b/3rdparty/sol2/docs/source/api/containers.rst index 81bbdc40584..8e084a908fd 100644 --- a/3rdparty/sol2/docs/source/api/containers.rst +++ b/3rdparty/sol2/docs/source/api/containers.rst @@ -100,4 +100,4 @@ If you have a type that has ``begin`` or ``end`` member functions but don't prov namespace sol { template <> struct is_container<not_container> : std::false_type {}; - } + }
\ No newline at end of file diff --git a/3rdparty/sol2/docs/source/api/function.rst b/3rdparty/sol2/docs/source/api/function.rst index 93adedabe49..1056bd2fe95 100644 --- a/3rdparty/sol2/docs/source/api/function.rst +++ b/3rdparty/sol2/docs/source/api/function.rst @@ -82,13 +82,17 @@ This makes it much easier to work with multiple return values. Using ``std::tie` Calls the function. The second ``operator()`` lets you specify the templated return types using the ``my_func(sol::types<int, std::string>, ...)`` syntax. Function assumes there are no runtime errors, and thusly will call the ``atpanic`` function if an error does occur. + +.. _function-argument-handling: + +functions and argument passing +------------------------------ + .. note:: All arguments are forwarded. Unlike :doc:`get/set/operator[] on sol::state<state>` or :doc:`sol::table<table>`, value semantics are not used here. It is forwarding reference semantics, which do not copy/move unless it is specifically done by the receiving functions / specifically done by the user. -.. _function-argument-handling: - .. note:: This also means that you should pass and receive arguments in certain ways to maximize efficiency. For example, ``sol::table``, ``sol::object``, ``sol::userdata`` and friends are fairly cheap to copy, and should simply by taken as values. This includes primitive types like ``int`` and ``double``. However, C++ types -- if you do not want copies -- should be taken as ``const type&`` or ``type&``, to save on copies if it's important. Note that taking references from Lua also means you can modify the data inside of Lua directly, so be careful. Lua by default deals with things mostly by reference (save for primitive types). diff --git a/3rdparty/sol2/docs/source/api/resolve.rst b/3rdparty/sol2/docs/source/api/resolve.rst index d8811d43f5c..193e2fae80f 100644 --- a/3rdparty/sol2/docs/source/api/resolve.rst +++ b/3rdparty/sol2/docs/source/api/resolve.rst @@ -7,9 +7,9 @@ utility to pick overloaded C++ function calls :caption: function: resolve C++ overload template <typename... Args, typename F> - auto resolve( F f ); + constexpr auto resolve( F f ); -``resolve`` is a function that is meant to help users pick a single function out of a group of overloaded functions in C++. You can use it to pick overloads by specifying the signature as the first template argument. Given a collection of overloaded functions: +``resolve`` is a function that is meant to help users pick a single function out of a group of overloaded functions in C++. It works for *both member and free functions* You can use it to pick overloads by specifying the signature as the first template argument. Given a collection of overloaded functions: .. code-block:: cpp :linenos: @@ -18,6 +18,12 @@ utility to pick overloaded C++ function calls int overloaded(int x, int y); int overloaded(int x, int y, int z); + struct thing { + int overloaded(int x); + int overloaded(int x, int y); + int overloaded(int x, int y, int z); + }; + You can disambiguate them using ``resolve``: .. code-block:: cpp @@ -26,6 +32,7 @@ You can disambiguate them using ``resolve``: auto one_argument_func = resolve<int(int)>( overloaded ); auto two_argument_func = resolve<int(int, int)>( overloaded ); auto three_argument_func = resolve<int(int, int, int)>( overloaded ); + auto member_three_argument_func = resolve<int(int, int, int)>( &thing::overloaded ); This resolution becomes useful when setting functions on a :doc:`table<table>` or :doc:`state_view<state>`: @@ -37,3 +44,20 @@ This resolution becomes useful when setting functions on a :doc:`table<table>` o lua.set_function("a", resolve<int(int)>( overloaded ) ); lua.set_function("b", resolve<int(int, int)>( overloaded )); lua.set_function("c", resolve<int(int, int, int)>( overloaded )); + + +It can also be used with :doc:`sol::c_call<c_call>`: + +.. code-block:: cpp + :linenos: + + sol::state lua; + + auto f = sol::c_call< + decltype(sol::resolve<int(int, int)>(&overloaded)), + sol::resolve<int(int, int)>(&overloaded) + >; + lua.set_function("f", f); + + lua.script("f(1, 2)"); + |