out_value.rst 1.5 KB

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