File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,22 +44,27 @@ class Config final
4444 }
4545 }
4646
47- value_type get (string_view_type key)
47+ template <typename T>
48+ T get (string_view_type key)
4849 {
49- if (!std::regex_match (key, m_what, m_conf_reg )) {
50+ if (!std::regex_match (key, m_what, m_reg )) {
5051 throw std::runtime_error (" config key error" );
5152 }
5253
5354 auto w1 = m_what[1 ].str ();
5455 auto w2 = m_what[2 ].str ();
5556
56- return luabridge::getGlobal (
57- m_vm.get (), w1.c_str ())[w2];
57+ using namespace luabridge ;
58+
59+ auto v = getGlobal (
60+ m_vm.get (), w1.c_str ());
61+
62+ return LuaRef_cast<T>(v[w2]);
5863 }
5964private:
6065 vm_type m_vm {luaL_newstate (), lua_close};
6166
62- regex_type m_conf_reg {R"( ^(\w+)\.(\w+)$)" };
67+ regex_type m_reg {R"( ^(\w+)\.(\w+)$)" };
6368 match_type m_what;
6469};
6570
Original file line number Diff line number Diff line change 3737{
3838 cout << " hello cpp_study server" << endl;
3939
40+ Config conf;
41+ conf.load (" ./conf.lua" );
42+
4043 Summary sum;
4144 std::atomic_int count {0 };
4245
8689 }
8790 };
8891
89- Config conf;
90- conf.load (" ./conf.lua" );
91-
92- string listen_addr = conf.get (" config.zmq_ipc_addr" );
93-
94- auto fu = std::async (cycle, listen_addr);
92+ auto fu = std::async (cycle,
93+ conf.get <string>(" config.zmq_ipc_addr" ));
9594
9695 fu.wait ();
9796}
You can’t perform that action at this time.
0 commit comments