*** empty log message ***
[luabind.git] / test / test_construction.cpp
blobb389d3f1f066a44badd7f9952dafbe7147d8a660
1 #include "test.h"
3 namespace
5 LUABIND_ANONYMOUS_FIX int feedback = 0;
6 LUABIND_ANONYMOUS_FIX int feedback2 = 0;
8 struct A
10 A(int a) { feedback = a; }
11 A(const A&) { feedback = 21; }
12 A() { feedback = 20; }
13 ~A() { feedback = -1; }
17 void f(A*, const A&) {}
19 struct B: public A
21 B(int a):A(a) { feedback2 = a; }
22 B() { feedback2 = 20; }
23 ~B() { feedback2 = -1; }
26 struct C {};
28 } // anonymous namespace
30 bool test_construction()
32 using namespace luabind;
34 lua_State* L = lua_open();
35 lua_closer c(L);
36 int top = lua_gettop(L);
38 open(L);
40 module(L)
42 class_<A>("A")
43 .def("f", &f)
44 .def(constructor<int>())
45 .def(constructor<const A&>())
46 .def(constructor<>()),
48 class_<B>("B")
49 .def(constructor<int>())
50 .def(constructor<>()),
52 class_<C>("C")
56 if (dostring2(L, "a = C()") == 0) return false;
57 lua_pop(L, 1); // pop error message
59 if (dostring(L, "a = A(4)")) return false;
60 if (feedback != 4) return false;
62 if (dostring(L, "a2 = A(a)")) return false;
63 if (feedback != 21) return false;
65 if (dostring(L, "b = B(6)")) return false;
66 if (feedback != 6) return false;
67 if (feedback2 != 6) return false;
69 if (dostring(L, "b2 = B()")) return false;
70 if (feedback != 20) return false;
71 if (feedback2 != 20) return false;
73 // if (dostring(L, "a:f(a)")) return false;
75 if (top != lua_gettop(L)) return false;
77 c.release();
78 if (feedback != -1) return false;
79 if (feedback2 != -1) return false;
81 return true;