6 using namespace luabind
;
7 LUABIND_ANONYMOUS_FIX
int feedback1
= 0;
8 LUABIND_ANONYMOUS_FIX
int feedback2
= 0;
9 LUABIND_ANONYMOUS_FIX
int feedback3
= 0;
10 LUABIND_ANONYMOUS_FIX
int feedback4
= 0;
11 LUABIND_ANONYMOUS_FIX
int feedback5
= 0;
13 void test_object_param(const object
& table
)
15 object current_object
;
16 current_object
= table
;
18 if (table
.type() == LUA_TTABLE
)
22 feedback2
= object_cast
<int>(table
["oh"]);
25 for (object::array_iterator i
= table
.abegin(); i
!= table
.aend(); ++i
)
27 feedback3
+= object_cast
<int>(*i
);
31 for (object::iterator j
= table
.begin(); j
!= table
.end(); ++j
)
33 feedback4
+= object_cast
<int>(*j
);
37 for (object::raw_iterator j
= table
.raw_begin(); j
!= table
.raw_end(); ++j
)
39 feedback5
+= object_cast
<int>(*j
);
49 if (table
.type() != LUA_TNIL
)
68 ~test_param() { feedback1
= 30; }
71 void test_match(const luabind::object
& o
)
76 void test_match(int i
)
81 function_
multiret(object a
, object b
)
90 } // anonymous namespace
94 using namespace luabind
;
96 lua_State
* L
= lua_open();
97 int top
= lua_gettop(L
);
109 std::cout
<< object_cast
<int>(a
) << ", " << object_cast
<int>(b
) << "\n";
111 (a
, b
, c
) = multiret(a
, b
);
113 std::cout
<< object_cast
<int>(a
) << ", " << object_cast
<int>(b
) << ", " << object_cast
<int>(c
) << "\n";
118 def("test_object_param", &test_object_param
),
119 def("test_fun", &test_fun
),
120 def("test_match", (void(*)(const luabind::object
&))&test_match
),
121 def("test_match", (void(*)(int))&test_match
),
123 class_
<test_param
>("test_param")
124 .def(constructor
<>())
127 dostring(L
, "t = 2");
128 dostring(L
, "test_object_param(t)");
129 if (feedback1
!= 2) return false;
130 if (feedback2
!= 1) return false;
132 dostring(L
, "test_object_param(nil)");
133 if (feedback1
!= 2) return false;
134 if (feedback2
!= 2) return false;
136 dostring(L
, "t = { ['oh'] = 4, 3, 5, 7, 13 }");
137 dostring(L
, "test_object_param(t)");
138 if (feedback1
!= 1) return false;
139 if (feedback2
!= 4) return false;
140 if (feedback3
!= 28) return false;
141 if (feedback4
!= 32) return false;
142 if (feedback5
!= 32) return false;
144 object g
= get_globals(L
);
147 if (t
.type() != LUA_TTABLE
) return false;
149 object blurp
= t
["blurp"];
150 if (object_cast
<int>(blurp
) != 5) return false;
152 object fun
= g
["test_fun"];
154 if (object_cast
<int>(ret
) != 42) return false;
155 if (feedback1
!= 3) return false;
157 dostring(L
, "function test_param_policies(x, y) end");
158 object test_param_policies
= g
["test_param_policies"];
159 int a
= test_param_policies
.type();
160 if (a
!= LUA_TFUNCTION
) return false;
161 // call the function and tell lua to adopt the pointer passed as first argument
162 test_param_policies(5, new test_param())[adopt(_2
)];
164 dostring(L
, "test_match(7)");
165 if (feedback1
!= 27) return false;
166 dostring(L
, "test_match('oo')");
167 if (feedback1
!= 28) return false;
169 dostring(L
, "function test_object_policies(a) glob = a\nreturn 6\nend");
170 object test_object_policies
= g
["test_object_policies"];
171 object ret_val
= test_object_policies("teststring")[detail::null_type()];
172 if (object_cast
<int>(ret_val
) != 6) return false;
173 if (object_cast
<std::string
>(g
["glob"]) != "teststring") return false;
174 if (object_cast
<std::string
>(g
.at("glob")) != "teststring") return false;
175 if (object_cast
<std::string
>(g
.raw_at("glob")) != "teststring") return false;
178 if (top
!= lua_gettop(L
)) return false;
182 // make sure lua adopted the pointer by checking that it has been deleted
183 if (feedback1
!= 30) return false;