From bba46dda8b3ca1491775cd6abd06b7c622fbd20a Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sat, 6 Dec 2014 18:47:57 +0300 Subject: luabind-test: test class binding --- src/luabind-test.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/luabind-test.cpp b/src/luabind-test.cpp index 45efb3d..0df7f19 100644 --- a/src/luabind-test.cpp +++ b/src/luabind-test.cpp @@ -1,4 +1,6 @@ #include +#include + #include #include @@ -7,6 +9,20 @@ void greet() std::cout << "hello world!\n"; } +class Test { +public: + Test(std::string name): + name_(name) { + } + + std::string name() const { + return name_; + } + +private: + std::string name_; +}; + extern "C" int init(lua_State* L) { using namespace luabind; @@ -15,7 +31,10 @@ extern "C" int init(lua_State* L) module(L) [ - def("greet", &greet) + def("greet", &greet), + class_("Test") + .def(constructor()) + .def("name", &Test::name) ]; return 0; @@ -26,4 +45,5 @@ int main() lua_State* L = luaL_newstate(); init(L); luaL_dostring(L, "greet()"); + luaL_dostring(L, "t = Test('123'); assert(t:name() == '123'"); } -- cgit v0.12