Teach adopt() to hold the adopted pointer in custom pointer type.
[luabind.git] / test / test_extend_class_in_lua.cpp
blob0323afc7dab283ec316bc93739053ec22d972d49
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)
5 #include "test.hpp"
6 #include <luabind/luabind.hpp>
8 struct CppClass
10 int f(int x)
12 return x;
16 void test_main(lua_State* L)
18 using namespace luabind;
20 module(L) [
21 class_<CppClass>("CppClass")
22 .def(constructor<>())
23 .def("f", &CppClass::f)
26 DOSTRING(L,
27 "function CppClass:f_in_lua(x)\n"
28 " return self:f(x) * 2\n"
29 "end\n"
32 DOSTRING(L,
33 "x = CppClass()\n"
34 "assert(x:f(1) == 1)\n"
35 "assert(x:f_in_lua(1) == 2)\n"