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>
29 int f_(int a
) { return 2; }
30 int f__(int a
) { return 3; }
32 int g_(int) { return 5; }
35 struct test_class
: counted_type
<test_class
>
43 struct test_class2
: counted_type
<test_class2
>
46 int string_string(std::string
const& s1
, std::string
const& s2
)
54 COUNTER_GUARD(test_class
);
55 COUNTER_GUARD(test_class2
);
59 using namespace luabind
;
63 class_
<test_class2
>("test_class2")
65 .def("string_string", &test_class2::string_string
)
70 class_
<test_class
>("test_class")
72 .def_readonly("test", &test_class::test
)
77 .def("inner_fun2", &f
) // this should become static
109 DOSTRING(L
, "assert(test.f() == 1)");
110 DOSTRING(L
, "assert(test.f(3) == 2)");
111 DOSTRING(L
, "assert(test.test_class.inner_fun() == 1)");
113 "a = test.test_class()\n"
114 "assert(a.test == 1)");
115 DOSTRING(L
, "assert(a.inner_fun2() == 1)"); // free function
117 "b = test.test_class.val2\n"
119 DOSTRING(L
, "assert(test.inner.g() == 4)");
120 DOSTRING(L
, "assert(test.inner.g(7) == 5)");
121 DOSTRING(L
, "assert(test.inner.f(4) == 3)");
122 DOSTRING(L
, "assert(test.inner.h() == 6)");