5 using namespace luabind
;
12 void test_object_param(const object
& table
)
14 if (table
.type() == LUA_TTABLE
)
18 feedback2
= object_cast
<int>(table
["oh"]);
21 for (object::array_iterator i
= table
.abegin(); i
!= table
.aend(); ++i
)
23 feedback3
+= object_cast
<int>(*i
);
27 for (object::iterator j
= table
.begin(); j
!= table
.end(); ++j
)
29 feedback4
+= object_cast
<int>(*j
);
33 for (object::raw_iterator j
= table
.raw_begin(); j
!= table
.raw_end(); ++j
)
35 feedback5
+= object_cast
<int>(*j
);
45 if (table
.type() != LUA_TNIL
)
64 ~test_param() { feedback1
= 30; }
67 void test_match(const luabind::object
& o
)
72 void test_match(int i
)
77 } // anonymous namespace
81 using namespace luabind
;
83 lua_State
* L
= lua_open();
84 int top
= lua_gettop(L
);
88 function(L
, "test_object_param", &test_object_param
);
89 function(L
, "test_fun", &test_fun
);
90 function(L
, "test_match", (void(*)(const luabind::object
&))&test_match
);
91 function(L
, "test_match", (void(*)(int))&test_match
);
92 class_
<test_param
>(L
, "test_param")
97 dostring(L
, "test_object_param(t)");
98 if (feedback1
!= 2) return false;
99 if (feedback2
!= 1) return false;
101 dostring(L
, "test_object_param(nil)");
102 if (feedback1
!= 2) return false;
103 if (feedback2
!= 2) return false;
105 dostring(L
, "t = { ['oh'] = 4, 3, 5, 7, 13 }");
106 dostring(L
, "test_object_param(t)");
107 if (feedback1
!= 1) return false;
108 if (feedback2
!= 4) return false;
109 if (feedback3
!= 28) return false;
110 if (feedback4
!= 32) return false;
111 if (feedback5
!= 32) return false;
113 object g
= get_globals(L
);
116 if (t
.type() != LUA_TTABLE
) return false;
118 object blurp
= t
["blurp"];
119 if (object_cast
<int>(blurp
) != 5) return false;
121 object fun
= g
["test_fun"];
123 if (object_cast
<int>(ret
) != 42) return false;
124 if (feedback1
!= 3) return false;
126 dostring(L
, "function test_param_policies(x, y) end");
127 object test_param_policies
= g
["test_param_policies"];
128 int a
= test_param_policies
.type();
129 // call the function and tell lua to adopt the pointer passed as first argument
130 test_param_policies(5, new test_param())[adopt(_2
)];
132 dostring(L
, "test_match(7)");
133 if (feedback1
!= 27) return false;
134 dostring(L
, "test_match('oo')");
135 if (feedback1
!= 28) return false;
137 dostring(L
, "function test_object_policies(a) glob = a\nreturn 6\nend");
138 object test_object_policies
= g
["test_object_policies"];
139 object ret_val
= test_object_policies("teststring")[detail::null_type()];
140 if (object_cast
<int>(ret_val
) != 6) return false;
141 if (object_cast
<std::string
>(g
["glob"]) != "teststring") return false;
142 if (object_cast
<std::string
>(g
.at("glob")) != "teststring") return false;
143 if (object_cast
<std::string
>(g
.raw_at("glob")) != "teststring") return false;
146 if (top
!= lua_gettop(L
)) return false;
150 // make sure lua adopted the pointer by checking that it has been deleted
151 if (feedback1
!= 30) return false;