Skip to content

Commit 4b3fcbe

Browse files
committed
luajit.cpp
1 parent 8ff92bf commit 4b3fcbe

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

section4/luajit.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2020 by Chrono
22
//
3-
// g++ luajit.cpp -std=c++11 -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl -o a.out;./a.out
3+
// g++ luajit.cpp -std=c++11 -I../common -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl -o a.out;./a.out
4+
// g++ luajit.cpp -std=c++11 -I../common -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl -O0 -g -o a.out
45
//
56
// g++ luajit.cpp -std=c++11 -I/usr/local/include/luajit-2.1 /usr/local/lib/libluajit-5.1.a -ldl -o a.out;./a.out
67
// g++ luajit.cpp -std=c++11 -I/usr/local/include/luajit-2.1 -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lluajit-5.1 -ldl -o a.out;./a.out
@@ -15,19 +16,54 @@ extern "C" {
1516
#include <lauxlib.h>
1617
}
1718

19+
#include <LuaBridge/LuaBridge.h>
20+
//namespace lua = luabridge;
21+
using namespace luabridge;
22+
23+
using namespace std;
24+
25+
class LuaState final
26+
{
27+
public:
28+
using lua_state_t = decltype(luaL_newstate());
29+
private:
30+
lua_state_t L = nullptr;
31+
public:
32+
LuaState()
33+
{
34+
L = luaL_newstate();
35+
}
36+
37+
~LuaState()
38+
{
39+
lua_close(L);
40+
}
41+
public:
42+
operator lua_state_t() const
43+
{
44+
return L;
45+
}
46+
};
47+
1848
void case1()
1949
{
2050
auto L = luaL_newstate();
2151
assert(L);
2252

2353
luaL_openlibs(L);
2454

55+
auto package = getGlobal(L, "package");
56+
57+
auto path = package["path"];
58+
59+
cout << path << endl;
60+
2561
lua_close(L);
2662
}
2763

2864
int main()
2965
{
30-
using namespace std;
66+
case1();
3167

3268
cout << "luajit demo" << endl;
3369
}

0 commit comments

Comments
 (0)