pointer extraction for holder_types works for pointer_converter.
[luabind.git] / test / test_held_type.cpp
blob9ddfd51855453eed0db6685611e94d05dfe2b796
1 #include <boost/shared_ptr.hpp>
4 namespace luabind
6 namespace detail
8 template<class T>
9 T* get_pointer(boost::shared_ptr<T>& p) { return p.get(); }
13 #include "test.h"
15 namespace
18 LUABIND_ANONYMOUS_FIX int feedback = 0;
20 struct held_type_test
22 held_type_test(): val(4) { feedback = 3; }
23 ~held_type_test() { feedback = 1; }
24 int val;
27 void tester(held_type_test* t)
29 if (t->val == 4) feedback = 2;
32 } // anonymous namespace
35 bool test_held_type()
37 // This feature is not finished yet
39 using namespace luabind;
42 lua_State* L = lua_open();
43 lua_closer c(L);
44 int top = lua_gettop(L);
46 open(L);
48 function(L, "tester", &tester);
50 class_<held_type_test, boost::shared_ptr<held_type_test> >("held_type_test")
51 .def(constructor<>())
52 .commit(L)
55 object g = get_globals(L);
56 g["test"] = boost::shared_ptr<held_type_test>(new held_type_test());
57 if (dostring(L, "tester(test)")) return false;
58 if (feedback != 2) return false;
59 if (dostring(L, "a = held_type_test()"))
60 if (feedback != 3) return false;
61 if (top != lua_gettop(L)) return false;
64 if (feedback != 1) return false;
66 return true;