- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_memory.cpp
More file actions
Latest commit
69 lines (54 loc) · 1.12 KB
/
Copy pathscript_memory.cpp
File metadata and controls
69 lines (54 loc) · 1.12 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
#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)
{
printf("コンストラクタ\n");
}
~piyo()
{
printf("デストラクタ\n");
}
};
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));
}
if (luaL_loadfile(L, "test2.lua") || lua_pcall(L, 0, 0, 0)) {
perror(lua_tostring(L, -1));
}
clock_t first = clock();
luabind::call_function<piyo>(L, "GetP");
clock_t second = clock();
// Luaを閉じる
lua_close(L);
// スクリプトでコンストラクタを呼んでメモリを確保した場合、
// Lua を閉じたときに解放される。
printf("sec : %f", (float)(second - first) / CLOCKS_PER_SEC);
getchar();
return0;
}