Add missing index_tuple.hpp header.
[luabind.git] / doc / out_value.rst
blobe337eb0be2694501c8294cb8115bdd706d221e13
1 out_value
2 ----------------
4 Motivation
5 ~~~~~~~~~~
7 This policy makes it possible to wrap functions that take non-const references
8 or pointer to non-const as it's parameters with the intention to write return 
9 values to them. Since it's impossible to pass references to primitive types
10 in lua, this policy will add another return value with the value after the
11 call. If the function already has one return value, one instance of this
12 policy will add another return value (read about multiple return values in
13 the lua manual).
15 Defined in
16 ~~~~~~~~~~
18 .. parsed-literal::
20     #include <luabind/out_value_policy.hpp>
22 Synopsis
23 ~~~~~~~~
25 .. parsed-literal::
27     out_value(index, policies = none)
30 Parameters
31 ~~~~~~~~~~
33 =============== =============================================================
34 Parameter       Purpose
35 =============== =============================================================
36 ``index``       The index of the parameter to be used as an out parameter.
37 ``policies``    The policies used internally to convert the out parameter
38                 to/from Lua. ``_1`` means **to** C++, ``_2`` means **from**
39                 C++.
40 =============== =============================================================
42 Example
43 ~~~~~~~
45 .. parsed-literal::
47     void f1(float& val) { val = val + 10.f; }
48     void f2(float\* val) { \*val = \*val + 10.f; }
50     module(L)
51     [
52         def("f", &f, **out_value(_1)**)
53     ];
55     Lua 5.0  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
56     > print(f1(10))
57     20
58     > print(f2(10))
59     20