summaryrefslogtreecommitdiffstats
path: root/src/luabind-test.cpp
diff options
context:
space:
mode:
authorBoris Nagaev <bnagaev@gmail.com>2014-12-06 15:47:57 (GMT)
committerBoris Nagaev <bnagaev@gmail.com>2014-12-06 19:11:16 (GMT)
commitbba46dda8b3ca1491775cd6abd06b7c622fbd20a (patch)
treec05d23ff4af52c3ce02226e9a58014d892223d28 /src/luabind-test.cpp
parent748ad97ef02fa9ff4c0e97d6546864f75f0b4753 (diff)
downloadmxe-bba46dda8b3ca1491775cd6abd06b7c622fbd20a.zip
mxe-bba46dda8b3ca1491775cd6abd06b7c622fbd20a.tar.gz
mxe-bba46dda8b3ca1491775cd6abd06b7c622fbd20a.tar.bz2
luabind-test: test class binding
Diffstat (limited to 'src/luabind-test.cpp')
-rw-r--r--src/luabind-test.cpp22
1 files changed, 21 insertions, 1 deletions
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 <iostream>
+#include <string>
+
#include <luabind/luabind.hpp>
#include <lua.hpp>
@@ -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>("Test")
+ .def(constructor<std::string>())
+ .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'");
}