- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_bind.cpp
More file actions
Latest commit
72 lines (57 loc) · 1.09 KB
/
Copy pathtime_bind.cpp
File metadata and controls
72 lines (57 loc) · 1.09 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<lua.hpp>
#include<luabind/lua_include.hpp>
#include<luabind/luabind.hpp>
#include<luabind/operator.hpp>
#include<time.h>
voidhoge(constint num)
{
printf("%d\n", num);
}
classpiyo
{
public:
int n_;
piyo() { n_ = 0; }
};
intmain(int argc, char* argv[])
{
// Luaを開く
lua_State* L = luaL_newstate();
luaL_openlibs(L);
// luabindを開く
luabind::open(L);
luabind::module(L)
[
luabind::def("hoge", &hoge),
luabind::class_<piyo>("piyo")
.def(luabind::constructor<>())
.def_readwrite("n_", &piyo::n_)
];
// Luaスクリプトを開く
if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0)) {
perror(lua_tostring(L, -1));
}
piyo p;
clock_t first = clock();
/* luabind */
#if1
while (p.n_ < 100000)// 5273, 5513, 5370, 5464, 5490
{
luabind::call_function<void>(L, "update", boost::ref(p));
}
#endif
/* c++ */
#if0
while (p.n_ < 100000)// 3742, 3696, 3935, 3680, 3680
{
p.n_ = p.n_ + 1;
greet(p.n_);
}
#endif
clock_t second = clock();
// Luaを閉じる
lua_close(L);
printf("sec : %f", (float)(second - first) / CLOCKS_PER_SEC);
getchar();
return0;
}