test_shared_ptr.cpp 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright Daniel Wallin 2009. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "test.hpp"
  5. #include <luabind/luabind.hpp>
  6. #include <luabind/shared_ptr_converter.hpp>
  7. struct X
  8. {
  9. X(int value)
  10. : value(value)
  11. {}
  12. int value;
  13. };
  14. int get_value(boost::shared_ptr<X> const& p)
  15. {
  16. return p->value;
  17. }
  18. boost::shared_ptr<X> filter(boost::shared_ptr<X> const& p)
  19. {
  20. return p;
  21. }
  22. void test_main(lua_State* L)
  23. {
  24. using namespace luabind;
  25. module(L) [
  26. class_<X>("X")
  27. .def(constructor<int>()),
  28. def("get_value", &get_value),
  29. def("filter", &filter)
  30. ];
  31. DOSTRING(L,
  32. "x = X(1)\n"
  33. "assert(get_value(x) == 1)\n"
  34. );
  35. DOSTRING(L,
  36. "assert(x == filter(x))\n"
  37. );
  38. }