Skip to content

Commit b7016f7

Browse files
committed
luajit.cpp
1 parent 4b3fcbe commit b7016f7

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

section4/luajit.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@ using namespace luabridge;
2222

2323
using namespace std;
2424

25-
class LuaState final
25+
class MyLuaState final
2626
{
2727
public:
2828
using lua_state_t = decltype(luaL_newstate());
2929
private:
3030
lua_state_t L = nullptr;
3131
public:
32-
LuaState()
32+
MyLuaState()
3333
{
3434
L = luaL_newstate();
35+
assert(L);
36+
37+
luaL_openlibs(L);
3538
}
3639

37-
~LuaState()
40+
~MyLuaState()
3841
{
3942
lua_close(L);
4043
}
@@ -43,22 +46,22 @@ class LuaState final
4346
{
4447
return L;
4548
}
49+
public:
50+
MyLuaState(const MyLuaState&) = delete;
51+
MyLuaState& operator=(const MyLuaState&) = delete;
4652
};
4753

4854
void case1()
4955
{
50-
auto L = luaL_newstate();
51-
assert(L);
52-
53-
luaL_openlibs(L);
56+
MyLuaState L;
5457

5558
auto package = getGlobal(L, "package");
5659

5760
auto path = package["path"];
61+
auto cpath = package["cpath"];
5862

5963
cout << path << endl;
60-
61-
lua_close(L);
64+
cout << cpath << endl;
6265
}
6366

6467
int main()

0 commit comments

Comments
 (0)