1 #include <boost/tokenizer.hpp>
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");
48 } // anonymous namespace
51 bool test_lua_classes()
53 using namespace luabind
;
56 lua_State
* L
= lua_open();
59 int top
= lua_gettop(L
);
63 class_
<base
, baseWrap
>(L
, "base")
65 .def("f", &baseWrap::fS
)
68 class_
<simple_class
>(L
, "simple_class")
70 .def("f", &simple_class::f
)
73 dostring(L
, "class 'derived' (base)\n"
74 "function derived:__init() super() end\n"
75 "function derived:f() return 'derived -> ' .. base.f(self) end\n");
77 dostring(L
, "function create_derived() return derived() end");
79 base
* ptr
= call_function
<base
*>(L
, "create_derived");
81 if (std::string("derived -> base") != ptr
->f()) return false;
83 dostring(L
, "class 'simple_derative' (simple_class)");
84 dostring(L
, "function simple_derative:__init() super() end\n");
85 dostring(L
, "a = simple_derative()");
87 if (feedback
!= 3) return false;
89 dostring(L
, "class 'simple_lua_class'\n");
90 dostring(L
, "function simple_lua_class:__init()\n"
94 "function simple_lua_class:f()\n"
97 dostring(L
, "a = simple_lua_class()");
99 if (feedback
!= 3) return false;
100 object g
= get_globals(L
)["g"];
101 if (object_cast
<int>(g
) != 5) return false;
103 if (top
!= lua_gettop(L
)) return false;
105 dostring(L
, "a = derived()");
108 if (feedback
!= -1) return false;