summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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'");
}