3 #include <luabind/out_value_policy.hpp>
4 #include <luabind/return_reference_to_policy.hpp>
5 #include <luabind/copy_policy.hpp>
10 LUABIND_ANONYMOUS_FIX
int feedback
= 0;
12 struct policies_test_class
16 policies_test_class() { feedback
++; }
17 policies_test_class(const char* name
): name_(name
) { feedback
++; }
18 ~policies_test_class() { feedback
--; }
20 policies_test_class
* make(const char* name
) const
22 return new policies_test_class(name
);
25 void f(policies_test_class
* p
) { delete p
; }
27 const policies_test_class
* internal_ref() { return this; }
29 policies_test_class
* self_ref()
35 policies_test_class(const policies_test_class
&) {}
38 policies_test_class global
;
40 void out_val(float* f
) { *f
= 3.f
; }
41 policies_test_class
* copy_val() { return &global
; }
43 struct secret_type
{};
47 secret_type
* secret() { return &sec_
; }
49 } // anonymous namespace
55 using namespace luabind
;
57 lua_State
* L
= lua_open();
61 int top
= lua_gettop(L
);
67 class_
<policies_test_class
>("test")
69 .def("f", &policies_test_class::f
, adopt(_1
))
70 .def("make", &policies_test_class::make
, adopt(return_value
))
71 .def("internal_ref", &policies_test_class::internal_ref
, dependency(return_value
, self
))
72 .def("self_ref", &policies_test_class::self_ref
, return_reference_to(self
)),
74 def("out_val", &out_val
, pure_out_value(_1
)),
75 def("copy_val", ©_val
, copy(result
)),
76 def("secret", &secret
, discard_result
)
81 if (dostring(L
, "a = secret()")) return false;
84 if (dostring(L
, "a = copy_val()")) return false;
85 if (dostring(L
, "a = nil")) return false;
86 if (dostring(L
, "collectgarbage(0)")) return false;
87 if (feedback
!= 0) return false;
90 if (dostring(L
, "a = out_val()")) return false;
92 // return_reference_to
93 if (dostring(L
, "a = test()")) return false;
94 if (feedback
!= 1) return false;
95 if (dostring(L
, "b = a:self_ref()")) return false;
96 if (dostring(L
, "a = nil")) return false;
97 if (dostring(L
, "collectgarbage(0)")) return false;
98 if (feedback
!= 1) return false;
99 if (dostring(L
, "b = nil")) return false;
100 if (dostring(L
, "collectgarbage(0)")) return false;
101 if (feedback
!= 0) return false;
104 if (dostring(L
, "a = test()")) return false;
105 if (feedback
!= 1) return false;
106 if (dostring(L
, "b = a:internal_ref()")) return false;
107 if (dostring(L
, "a = nil")) return false;
108 if (dostring(L
, "collectgarbage(0)")) return false;
109 if (feedback
!= 1) return false;
110 if (dostring(L
, "b = nil")) return false;
111 if (dostring(L
, "collectgarbage(0)")) return false; // two gc-cycles because dependency-table won't be collected in the same cycle
112 if (dostring(L
, "collectgarbage(0)")) return false; // as the object_rep
113 if (feedback
!= 0) return false;
116 if (dostring(L
, "a = test()")) return false;
117 if (feedback
!= 1) return false;
118 if (dostring(L
, "b = a:make('tjosan')")) return false;
119 if (feedback
!= 2) return false;
120 if (dostring(L
, "a:f(b)")) return false;
122 if (top
!= lua_gettop(L
)) return false;
125 if (feedback
!= 0) return false;