| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <!DOCTYPE html>
- <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
- <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
-
-
- <title>Advanced Stack Interaction - Luwra</title>
-
- <link rel="shortcut icon" href="../img/favicon.ico">
-
- <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
- <link rel="stylesheet" href="../css/theme.css" type="text/css" />
- <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
- <link rel="stylesheet" href="../css/highlight.css">
-
- <script>
- // Current page data
- var mkdocs_page_name = "Advanced Stack Interaction";
- var mkdocs_page_input_path = "advanced.md";
- var mkdocs_page_url = "/advanced/";
- </script>
-
- <script src="../js/jquery-2.1.1.min.js"></script>
- <script src="../js/modernizr-2.8.3.min.js"></script>
- <script type="text/javascript" src="../js/highlight.pack.js"></script>
- <script src="../js/theme.js"></script>
-
- </head>
- <body class="wy-body-for-nav" role="document">
- <div class="wy-grid-for-nav">
-
- <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
- <div class="wy-side-nav-search">
- <a href=".." class="icon icon-home"> Luwra</a>
- <div role="search">
- <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
- <input type="text" name="q" placeholder="Search docs" />
- </form>
- </div>
- </div>
- <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
- <ul class="current">
-
- <li>
- <li class="toctree-l1 ">
- <a class="" href="..">Home</a>
-
- </li>
- <li>
-
- <li>
- <li class="toctree-l1 ">
- <a class="" href="../stack-interaction/">Stack Interaction</a>
-
- </li>
- <li>
-
- <li>
- <li class="toctree-l1 current">
- <a class="current" href="./">Advanced Stack Interaction</a>
-
- <ul>
-
- <li class="toctree-l3"><a href="#advanced-stack-interaction">Advanced stack interaction</a></li>
-
- <li><a class="toctree-l4" href="#invoke-a-callable-with-lua-values">Invoke a Callable with Lua values</a></li>
-
- <li><a class="toctree-l4" href="#invoke-a-function-with-lua-values">Invoke a function with Lua values</a></li>
-
-
- </ul>
-
- </li>
- <li>
-
- <li>
- <li class="toctree-l1 ">
- <a class="" href="../wrapping/">Wrapping</a>
-
- </li>
- <li>
-
- <li>
- <li class="toctree-l1 ">
- <a class="" href="../user-types/">User Types</a>
-
- </li>
- <li>
-
- </ul>
- </div>
-
- </nav>
- <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
-
- <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
- <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
- <a href="..">Luwra</a>
- </nav>
-
- <div class="wy-nav-content">
- <div class="rst-content">
- <div role="navigation" aria-label="breadcrumbs navigation">
- <ul class="wy-breadcrumbs">
- <li><a href="..">Docs</a> »</li>
-
-
-
- <li>Advanced Stack Interaction</li>
- <li class="wy-breadcrumbs-aside">
-
-
- <a href="https://github.com/vapourismo/luwra" class="icon icon-github"> Edit on GitHub</a>
-
-
- </li>
- </ul>
- <hr/>
- </div>
- <div role="main">
- <div class="section">
-
- <h1 id="advanced-stack-interaction">Advanced stack interaction</h1>
- <p>Instead of extracting every Lua value seperately and pushing the result of your C++ function back
- onto the stack again, you can use one of the following functions to make this process easier for
- you.</p>
- <h2 id="invoke-a-callable-with-lua-values">Invoke a Callable with Lua values</h2>
- <p>The function <a href="../reference/namespaceluwra.html#aa20e363f38b3ae5a168cf40365f5646a">direct</a> lets you specify a <em>stack signature</em> in order to extract the
- values and invoke a <code>Callable</code> with them.</p>
- <p>Consider the following:</p>
- <pre><code class="c++">string result = foo(luwra::read<string>(lua, n), luwra::read<int>(lua, n + 1));
- </code></pre>
- <p>It could be rewritting like this:</p>
- <pre><code class="c++">string result = luwra::direct<string(string, int)>(lua, n, foo);
- </code></pre>
- <p><strong>Note:</strong> The result of <code>foo</code> is not pushed onto the stack. Except for the extraction of Lua values,
- everything happens on the C++ side.</p>
- <h2 id="invoke-a-function-with-lua-values">Invoke a function with Lua values</h2>
- <p><a href="../reference/namespaceluwra.html#a839077ddd9c3d0565a40c574bc8e9555">apply</a> is similiar to <a href="../reference/namespaceluwra.html#aa20e363f38b3ae5a168cf40365f5646a">direct</a>. It differs from <code>direct</code> by providing
- specific overloads for function pointers and function objects. Although <code>direct</code> works with function pointers
- and function objects, it is often more convenient to use <code>apply</code> since it allows the compiler to
- infer the <em>stack signature</em> without providing a template parameter.</p>
- <p>Provided a function <code>foo</code> which has been declared as used in the example above:</p>
- <pre><code class="c++">string foo(string bar, int baz);
- // ... or with a function object
- function<string(string, int)> foo = /* magic */;
- </code></pre>
- <p>One would use <code>foo</code> like this:</p>
- <pre><code class="c++">string result = luwra::apply(lua, n, foo);
- </code></pre>
-
- </div>
- </div>
- <footer>
-
- <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
-
- <a href="../wrapping/" class="btn btn-neutral float-right" title="Wrapping">Next <span class="icon icon-circle-arrow-right"></span></a>
-
-
- <a href="../stack-interaction/" class="btn btn-neutral" title="Stack Interaction"><span class="icon icon-circle-arrow-left"></span> Previous</a>
-
- </div>
-
- <hr/>
- <div role="contentinfo">
- <!-- Copyright etc -->
-
- </div>
- Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
- </footer>
-
- </div>
- </div>
- </section>
- </div>
- <div class="rst-versions" role="note" style="cursor: pointer">
- <span class="rst-current-version" data-toggle="rst-current-version">
-
- <a href="https://github.com/vapourismo/luwra" class="icon icon-github" style="float: left; color: #fcfcfc"> GitHub</a>
-
-
- <span><a href="../stack-interaction/" style="color: #fcfcfc;">« Previous</a></span>
-
-
- <span style="margin-left: 15px"><a href="../wrapping/" style="color: #fcfcfc">Next »</a></span>
-
- </span>
- </div>
- </body>
- </html>
|