File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Copyright (c) 2020 by Chrono
2+
3+ #ifndef _HELLO_HPP
4+ #define _HELLO_HPP
5+
6+ #include " cpplang.hpp"
7+
8+ extern " C" {
9+ #include < luajit.h>
10+ #include < lualib.h>
11+ #include < lauxlib.h>
12+ }
13+
14+ #include < LuaBridge/LuaBridge.h>
15+
16+ BEGIN_NAMESPACE (cpp_study)
17+
18+ class Config final
19+ {
20+ public:
21+ using vm_type = std::shared_ptr<lua_State>;
22+ using value_type = luabridge::LuaRef;
23+
24+ // using string_type = std::string;
25+ using string_view_type = const std::string&;
26+ public:
27+ Config () noexcept
28+ {
29+ assert (m_vm);
30+
31+ luaL_openlibs (m_vm.get ());
32+ }
33+
34+ ~Config () = default ;
35+ public:
36+ void load (string_view_type filename)
37+ {
38+ auto status = luaL_dofile (m_vm.get (), filename.c_str ());
39+
40+ if (!status) {
41+ throw std::runtime_error (" failed to parse config" );
42+ }
43+ }
44+
45+ value_type get (string_view_type key) const
46+ {
47+ return luabridge::getGlobal (m_vm.get (), key.c_str ());
48+ }
49+ private:
50+ vm_type m_vm {luaL_newstate (), lua_close};
51+ };
52+
53+ END_NAMESPACE (cpp_study)
54+
55+ #endif // _HELLO_HPP
56+
File renamed without changes.
Original file line number Diff line number Diff line change 11// Copyright (c) 2020 by Chrono
22//
3- // g++ srv.cpp -std=c++14 -I../common -I../common/include -lzmq -lpthread -o a.out;./a.out
4- // g++ srv.cpp -std=c++14 -I../common -I../common/include -lzmq -lpthread -g -O0 -o a.out
5- // g++ srv.cpp -std=c++14 -I../common -I../common/include -lzmq -lpthread -g -O0 -o a.out;./a.out
3+ // g++ srv.cpp -std=c++14 -I../common -I../common/include -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl - lzmq -lpthread -o a.out;./a.out
4+ // g++ srv.cpp -std=c++14 -I../common -I../common/include -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl - lzmq -lpthread -g -O0 -o a.out
5+ // g++ srv.cpp -std=c++14 -I../common -I../common/include -I/usr/local/include/luajit-2.1 -lluajit-5.1 -ldl - lzmq -lpthread -g -O0 -o a.out;./a.out
66
77// #include <iostream>
88
99#include " cpplang.hpp"
1010#include " Summary.hpp"
1111#include " Zmq.hpp"
12+ #include " Config.hpp"
1213
1314// you should put json.hpp in ../common
1415#include " json.hpp"
@@ -38,6 +39,7 @@ int main()
3839 Summary sum;
3940 std::atomic_int count {0 };
4041
42+ // todo: try-catch
4143 auto cycle = [&](const auto & addr)
4244 {
4345 using zmq_ctx = ZmqContext<1 >;
@@ -59,6 +61,7 @@ int main()
5961
6062 // async process msg
6163
64+ // todo: try-catch
6265 std::async (std::launch::async,
6366 [&sum, &count](decltype (msg_ptr) ptr)
6467 {
You can’t perform that action at this time.
0 commit comments