1 // Copyright Daniel Wallin 2009. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5 #include "test.hpp"
6 #include <luabind/class_info.hpp>
7 #include <luabind/luabind.hpp>
8 #include <luabind/shared_ptr_converter.hpp>
9
10 #include <boost/shared_ptr.hpp>
11
12 struct Foo
13 {
FooFoo14 Foo() : m_baz(0) {}
15 int m_baz;
16 };
17
18 struct Bar
19 {
getFooBar20 boost::shared_ptr<Foo> getFoo() const { return m_foo; }
setFooBar21 void setFoo( boost::shared_ptr<Foo> foo ) { m_foo = foo; }
22
23 boost::shared_ptr<Foo> m_foo;
24 };
25
test_main(lua_State * L)26 void test_main(lua_State* L)
27 {
28 using namespace luabind;
29
30 bind_class_info(L);
31
32 module( L )
33 [
34 class_<Foo, boost::shared_ptr<Foo> >( "Foo" )
35 .def( constructor<>() )
36 .def_readwrite("baz", &Foo::m_baz),
37 class_<Bar, boost::shared_ptr<Bar> >( "Bar" )
38 .def( constructor<>() )
39 .property("fooz", &Bar::getFoo, &Bar::setFoo)
40 .def_readwrite("foo", &Bar::m_foo)
41 ];
42 dostring( L, "foo = Foo();");
43 dostring( L, "foo.baz = 42;");
44 dostring( L, "x = Bar();");
45 dostring( L, "x.fooz = foo;");
46 dostring( L, "print(type(x), class_info(x).name);");
47 dostring( L, "print(type(x.fooz), class_info(x.fooz).name);");
48 dostring( L, "print(type(x.foo), class_info(x.foo).name);"); // crashes here);
49 }
50