1 #include <boost/tokenizer.hpp>
7 LUABIND_ANONYMOUS_FIX
int feedback
= 0;
13 // std::cout << "~base\n";
17 virtual const char* f()
23 struct baseWrap
: base
26 luabind::object self_
;
27 baseWrap(const luabind::object
& self
): self_(self
) {}
29 static const char* fS(base
* obj
)
31 return obj
->base::f();
34 virtual const char* f()
36 return luabind::call_member
<const char*>(self_
, "f");
53 no_copy(const no_copy
&) {}
56 } // anonymous namespace
59 bool test_lua_classes()
61 using namespace luabind
;
64 lua_State
* L
= lua_open();
67 int top
= lua_gettop(L
);
71 class_
<no_copy
>(L
, "no copy");
73 class_
<base
, baseWrap
>(L
, "base")
75 .def("f", &baseWrap::fS
)
78 class_
<simple_class
>(L
, "simple_class")
80 .def("f", &simple_class::f
)
83 dostring(L
, "class 'derived' (base)\n"
84 "function derived:__init() super() end\n"
85 "function derived:f() return 'derived -> ' .. base.f(self) end\n");
87 dostring(L
, "function create_derived() return derived() end");
89 base
* ptr
= call_function
<base
*>(L
, "create_derived");
91 if (std::string("derived -> base") != ptr
->f()) return false;
93 dostring(L
, "class 'simple_derative' (simple_class)");
94 dostring(L
, "function simple_derative:__init() super() end\n");
95 dostring(L
, "a = simple_derative()");
97 if (feedback
!= 3) return false;
99 dostring(L
, "class 'simple_lua_class'\n");
100 dostring(L
, "function simple_lua_class:__init()\n"
102 "self.test_var = 1\n"
104 "function simple_lua_class:f()\n"
107 dostring(L
, "a = simple_lua_class()");
108 dostring(L
, "a:f()");
109 if (feedback
!= 3) return false;
110 object g
= get_globals(L
)["g"];
111 if (object_cast
<int>(g
) != 5) return false;
113 if (top
!= lua_gettop(L
)) return false;
115 dostring(L
, "a = derived()");
118 if (feedback
!= -1) return false;