blob: 0df7f19465d6c5cca2f348178403d5c79c7be16b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <iostream>
#include <string>
#include <luabind/luabind.hpp>
#include <lua.hpp>
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;
open(L);
module(L)
[
def("greet", &greet),
class_<Test>("Test")
.def(constructor<std::string>())
.def("name", &Test::name)
];
return 0;
}
int main()
{
lua_State* L = luaL_newstate();
init(L);
luaL_dostring(L, "greet()");
luaL_dostring(L, "t = Test('123'); assert(t:name() == '123'");
}
|