test_create_in_thread.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. int count = 0;
  7. struct X
  8. {
  9. X()
  10. {
  11. ++count;
  12. }
  13. ~X()
  14. {
  15. --count;
  16. }
  17. };
  18. struct Y
  19. {
  20. virtual ~Y()
  21. {}
  22. };
  23. struct Y_wrap : Y, luabind::wrap_base
  24. {};
  25. void test_main(lua_State* L)
  26. {
  27. using namespace luabind;
  28. module(L) [
  29. class_<X>("X")
  30. .def(constructor<>()),
  31. class_<Y, Y_wrap>("Y")
  32. .def(constructor<>())
  33. ];
  34. DOSTRING(L,
  35. "class 'Y_lua' (Y)\n"
  36. " function Y_lua.__init(self)\n"
  37. " Y.__init(self)\n"
  38. " end\n"
  39. );
  40. for (int i = 0; i < 100; ++i)
  41. {
  42. lua_State* thread = lua_newthread(L);
  43. int ref = luaL_ref(L, LUA_REGISTRYINDEX);
  44. DOSTRING(thread,
  45. "local x = X()\n"
  46. );
  47. DOSTRING(thread,
  48. "local y = Y_lua()\n"
  49. );
  50. luaL_unref(L, LUA_REGISTRYINDEX, ref);
  51. }
  52. }