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.
24 #include <luabind/luabind.hpp>
27 int f_(int a
) { return 2; }
28 int f__(int a
) { return 3; }
30 int g_(int) { return 5; }
33 struct test_class
: counted_type
<test_class
>
41 struct test_class2
: counted_type
<test_class2
>
44 int string_string(std::string
const& s1
, std::string
const& s2
)
48 COUNTER_GUARD(test_class
);
49 COUNTER_GUARD(test_class2
);
51 void test_main(lua_State
* L
)
53 using namespace luabind
;
57 class_
<test_class2
>("test_class2")
59 .def("string_string", &test_class2::string_string
)
64 class_
<test_class
>("test_class")
66 .def_readonly("test", &test_class::test
)
71 .def("inner_fun2", &f
) // this should become static
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)");
107 "a = test.test_class()\n"
108 "assert(a.test == 1)");
109 DOSTRING(L
, "assert(a.inner_fun2() == 1)"); // free function
111 "b = test.test_class.val2\n"
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)");