From a68d4239929802bca7131d4b97c2b8d149fbbcb9 Mon Sep 17 00:00:00 2001 From: cracyc Date: Tue, 15 Nov 2016 22:21:07 -0600 Subject: luaengine: use initializers (nw) --- 3rdparty/sol2/docs/source/api/resolve.rst | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to '3rdparty/sol2/docs/source/api/resolve.rst') 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 - 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( overloaded ); auto two_argument_func = resolve( overloaded ); auto three_argument_func = resolve( overloaded ); + auto member_three_argument_func = resolve( &thing::overloaded ); This resolution becomes useful when setting functions on a :doc:`table` or :doc:`state_view`: @@ -37,3 +44,20 @@ This resolution becomes useful when setting functions on a :doc:`table
` o lua.set_function("a", resolve( overloaded ) ); lua.set_function("b", resolve( overloaded )); lua.set_function("c", resolve( overloaded )); + + +It can also be used with :doc:`sol::c_call`: + +.. code-block:: cpp + :linenos: + + sol::state lua; + + auto f = sol::c_call< + decltype(sol::resolve(&overloaded)), + sol::resolve(&overloaded) + >; + lua.set_function("f", f); + + lua.script("f(1, 2)"); + -- cgit v1.2.3-70-g09d2