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");
52 no_copy(const no_copy
&) {}
55 } // anonymous namespace
58 bool test_lua_classes()
60 using namespace luabind
;
63 lua_State
* L
= lua_open();
66 int top
= lua_gettop(L
);
70 class_
<no_copy
>(L
, "no copy");
72 class_
<base
, baseWrap
>(L
, "base")
74 .def("f", &baseWrap::fS
)
77 class_
<simple_class
>(L
, "simple_class")
79 .def("f", &simple_class::f
)
82 dostring(L
, "class 'derived' (base)\n"
83 "function derived:__init() super() end\n"
84 "function derived:f() return 'derived -> ' .. base.f(self) end\n");
86 dostring(L
, "function create_derived() return derived() end");
88 base
* ptr
= call_function
<base
*>(L
, "create_derived");
90 if (std::string("derived -> base") != ptr
->f()) return false;
92 dostring(L
, "class 'simple_derative' (simple_class)");
93 dostring(L
, "function simple_derative:__init() super() end\n");
94 dostring(L
, "a = simple_derative()");
96 if (feedback
!= 3) return false;
98 dostring(L
, "class 'simple_lua_class'\n");
99 dostring(L
, "function simple_lua_class:__init()\n"
101 "self.test_var = 1\n"
103 "function simple_lua_class:f()\n"
106 dostring(L
, "a = simple_lua_class()");
107 dostring(L
, "a:f()");
108 if (feedback
!= 3) return false;
109 object g
= get_globals(L
)["g"];
110 if (object_cast
<int>(g
) != 5) return false;
112 if (top
!= lua_gettop(L
)) return false;
114 dostring(L
, "a = derived()");
117 if (feedback
!= -1) return false;