Add test for "class_info()".
[luabind.git] / test / test_scope.cpp
blob15c742e3b9634fadd4f55637ba2c4636d7e8389c
1 // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
23 #include "test.hpp"
24 #include <luabind/luabind.hpp>
26 int f() { return 1; }
27 int f_(int a) { return 2; }
28 int f__(int a) { return 3; }
29 int g() { return 4; }
30 int g_(int) { return 5; }
31 int h() { return 6; }
33 struct test_class : counted_type<test_class>
35 test_class()
36 : test(1)
38 int test;
41 struct test_class2 : counted_type<test_class2>
43 test_class2() {}
44 int string_string(std::string const& s1, std::string const& s2)
45 { return 1; }
48 COUNTER_GUARD(test_class);
49 COUNTER_GUARD(test_class2);
51 void test_main(lua_State* L)
53 using namespace luabind;
55 module(L)
57 class_<test_class2>("test_class2")
58 .def(constructor<>())
59 .def("string_string", &test_class2::string_string)
62 module(L, "test")
64 class_<test_class>("test_class")
65 .def(constructor<>())
66 .def_readonly("test", &test_class::test)
67 .scope
69 def("inner_fun", &f)
71 .def("inner_fun2", &f) // this should become static
72 .enum_("vals")
74 value("val1", 1),
75 value("val2", 2)
78 def("f", &f),
79 def("f", &f_),
81 namespace_("inner")
83 def("g", &g),
84 def("f", &f__)
87 namespace_("inner")
89 def("g", &g_)
94 module(L, "test")
96 namespace_("inner")
98 def("h", &h)
103 DOSTRING(L, "assert(test.f() == 1)");
104 DOSTRING(L, "assert(test.f(3) == 2)");
105 DOSTRING(L, "assert(test.test_class.inner_fun() == 1)");
106 DOSTRING(L,
107 "a = test.test_class()\n"
108 "assert(a.test == 1)");
109 DOSTRING(L, "assert(a.inner_fun2() == 1)"); // free function
110 DOSTRING(L,
111 "b = test.test_class.val2\n"
112 "assert(b == 2)");
113 DOSTRING(L, "assert(test.inner.g() == 4)");
114 DOSTRING(L, "assert(test.inner.g(7) == 5)");
115 DOSTRING(L, "assert(test.inner.f(4) == 3)");
116 DOSTRING(L, "assert(test.inner.h() == 6)");