File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
1848void 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
2864int main ()
2965{
30- using namespace std ;
66+ case1 () ;
3167
3268 cout << " luajit demo" << endl;
3369}
You can’t perform that action at this time.
0 commit comments