index.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>Advanced - Luwra</title>
  9. <link rel="shortcut icon" href="../img/favicon.ico">
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
  11. <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  12. <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  13. <link rel="stylesheet" href="../css/highlight.css">
  14. <script>
  15. // Current page data
  16. var mkdocs_page_name = "Advanced";
  17. var mkdocs_page_input_path = "advanced.md";
  18. var mkdocs_page_url = "/advanced/";
  19. </script>
  20. <script src="../js/jquery-2.1.1.min.js"></script>
  21. <script src="../js/modernizr-2.8.3.min.js"></script>
  22. <script type="text/javascript" src="../js/highlight.pack.js"></script>
  23. <script src="../js/theme.js"></script>
  24. </head>
  25. <body class="wy-body-for-nav" role="document">
  26. <div class="wy-grid-for-nav">
  27. <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
  28. <div class="wy-side-nav-search">
  29. <a href=".." class="icon icon-home"> Luwra</a>
  30. <div role="search">
  31. <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <ul class="current">
  38. <li>
  39. <li class="toctree-l1 ">
  40. <a class="" href="..">Home</a>
  41. </li>
  42. <li>
  43. <li>
  44. <li class="toctree-l1 ">
  45. <a class="" href="../basics/">Basics</a>
  46. </li>
  47. <li>
  48. <li>
  49. <li class="toctree-l1 current">
  50. <a class="current" href="./">Advanced</a>
  51. <ul>
  52. <li class="toctree-l3"><a href="#operating-on-lua-values-with-c-functions">Operating on Lua values with C++ functions</a></li>
  53. <li><a class="toctree-l4" href="#invoke-a-callable-with-lua-values">Invoke a Callable with Lua values</a></li>
  54. <li><a class="toctree-l4" href="#invoke-a-function-with-lua-values">Invoke a function with Lua values</a></li>
  55. </ul>
  56. </li>
  57. <li>
  58. <li>
  59. <li class="toctree-l1 ">
  60. <a class="" href="../miscellaneous/">Miscellaneous</a>
  61. </li>
  62. <li>
  63. </ul>
  64. </div>
  65. &nbsp;
  66. </nav>
  67. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  68. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  69. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  70. <a href="..">Luwra</a>
  71. </nav>
  72. <div class="wy-nav-content">
  73. <div class="rst-content">
  74. <div role="navigation" aria-label="breadcrumbs navigation">
  75. <ul class="wy-breadcrumbs">
  76. <li><a href="..">Docs</a> &raquo;</li>
  77. <li>Advanced</li>
  78. <li class="wy-breadcrumbs-aside">
  79. <a href="https://github.com/vapourismo/luwra" class="icon icon-github"> Edit on GitHub</a>
  80. </li>
  81. </ul>
  82. <hr/>
  83. </div>
  84. <div role="main">
  85. <div class="section">
  86. <h1 id="operating-on-lua-values-with-c-functions">Operating on Lua values with C++ functions</h1>
  87. <p>Instead of extracting every Lua value seperately and pushing the result of your C++ function back
  88. onto the stack again, you can use one of the following functions to make this process easier for you.</p>
  89. <h2 id="invoke-a-callable-with-lua-values">Invoke a Callable with Lua values</h2>
  90. <p>The function <a href="../reference/namespaceluwra.html#aa20e363f38b3ae5a168cf40365f5646a">direct</a>
  91. lets you specify a <em>stack signature</em> in order to extract the values and invoke a <code>Callable</code> with
  92. them.</p>
  93. <p>Consider the following:</p>
  94. <pre><code class="c++">string result = foo(luwra::read&lt;string&gt;(lua, n), luwra::read&lt;int&gt;(lua, n + 1));
  95. </code></pre>
  96. <p>It could be rewritting like this:</p>
  97. <pre><code class="c++">string result = luwra::direct&lt;string(string, int)&gt;(lua, n, foo);
  98. </code></pre>
  99. <p><strong>Note:</strong> The result of <code>foo</code> is not pushed onto the stack. Besides the extraction of Lua values
  100. everything happens on the C++ side.</p>
  101. <h2 id="invoke-a-function-with-lua-values">Invoke a function with Lua values</h2>
  102. <p><a href="../reference/namespaceluwra.html#a839077ddd9c3d0565a40c574bc8e9555">apply</a> is similiar to
  103. <a href="../reference/namespaceluwra.html#aa20e363f38b3ae5a168cf40365f5646a">direct</a>. The function <code>apply</code>
  104. provides specific overloads for function pointers and function objects. Although <code>direct</code> works
  105. with function pointers and function objects, it is often more convenient to use <code>apply</code> since it
  106. allows the compiler to infer the <em>stack signature</em> without providing a template parameter.</p>
  107. <p>Provided a function <code>foo</code> which has been declared as used in the example above:</p>
  108. <pre><code class="c++">string foo(string bar, int baz);
  109. // ... or with a function object
  110. std::function&lt;string(string, int)&gt; foo = /* magic */;
  111. </code></pre>
  112. <p>One would use <code>foo</code> like this:</p>
  113. <pre><code class="c++">string result = luwra::apply(lua, n, foo);
  114. </code></pre>
  115. </div>
  116. </div>
  117. <footer>
  118. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  119. <a href="../miscellaneous/" class="btn btn-neutral float-right" title="Miscellaneous">Next <span class="icon icon-circle-arrow-right"></span></a>
  120. <a href="../basics/" class="btn btn-neutral" title="Basics"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  121. </div>
  122. <hr/>
  123. <div role="contentinfo">
  124. <!-- Copyright etc -->
  125. </div>
  126. 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>.
  127. </footer>
  128. </div>
  129. </div>
  130. </section>
  131. </div>
  132. <div class="rst-versions" role="note" style="cursor: pointer">
  133. <span class="rst-current-version" data-toggle="rst-current-version">
  134. <a href="https://github.com/vapourismo/luwra" class="icon icon-github" style="float: left; color: #fcfcfc"> GitHub</a>
  135. <span><a href="../basics/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  136. <span style="margin-left: 15px"><a href="../miscellaneous/" style="color: #fcfcfc">Next &raquo;</a></span>
  137. </span>
  138. </div>
  139. </body>
  140. </html>