Teach adopt() to hold the adopted pointer in custom pointer type.
[luabind.git] / test / test_create_in_thread.cpp
blob65efed1e5f127813339b1aa0aa0e0e50576c9012
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)
5 #include "test.hpp"
6 #include <luabind/luabind.hpp>
8 int count = 0;
10 struct X
12 X()
14 ++count;
17 ~X()
19 --count;
23 struct Y
25 virtual ~Y()
29 struct Y_wrap : Y, luabind::wrap_base
30 {};
32 void test_main(lua_State* L)
34 using namespace luabind;
36 module(L) [
37 class_<X>("X")
38 .def(constructor<>()),
40 class_<Y, Y_wrap>("Y")
41 .def(constructor<>())
44 DOSTRING(L,
45 "class 'Y_lua' (Y)\n"
46 " function Y_lua.__init(self)\n"
47 " Y.__init(self)\n"
48 " end\n"
51 for (int i = 0; i < 100; ++i)
53 lua_State* thread = lua_newthread(L);
54 int ref = luaL_ref(L, LUA_REGISTRYINDEX);
56 DOSTRING(thread,
57 "local x = X()\n"
60 DOSTRING(thread,
61 "local y = Y_lua()\n"
64 luaL_unref(L, LUA_REGISTRYINDEX, ref);