test_adopt_wrapper.cpp 704 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright Daniel Wallin 2008. 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/adopt_policy.hpp>
  7. struct X
  8. {
  9. virtual ~X()
  10. {}
  11. };
  12. struct X_wrap : X, luabind::wrap_base
  13. {};
  14. X* make()
  15. {
  16. return new X;
  17. }
  18. void take(X* p)
  19. {
  20. delete p;
  21. }
  22. void test_main(lua_State* L)
  23. {
  24. using namespace luabind;
  25. module(L) [
  26. class_<X, X_wrap>("X"),
  27. def("make", &make, adopt(result)),
  28. def("take", &take, adopt(_1))
  29. ];
  30. DOSTRING(L,
  31. "take(make())\n"
  32. );
  33. }