Skip to content

Commit

Permalink
Plugins/Context: removed C-style array ctor and use
Browse files Browse the repository at this point in the history
This likely existed because this code was added in 2014 before we switched to C++11
and initializer lists.
  • Loading branch information
Vultraz committed Oct 19, 2019
1 parent ab01973 commit 3c01a43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
23 changes: 5 additions & 18 deletions src/scripting/plugins/context.hpp
Expand Up @@ -36,24 +36,11 @@ class plugins_context {
typedef std::function<config(config)> accessor_function;
struct aReg { char const * name; accessor_function func; };

using reg_vec = std::vector<Reg>;
using areg_vec = std::vector<aReg>;

plugins_context( const std::string & name );
plugins_context( const std::string & name, const std::vector<Reg>& callbacks, const std::vector<aReg>& accessors);
template<int N, int M>
plugins_context( const std::string & name, const Reg (& callbacks)[N], const aReg (& accessors)[M])
: name_(name)
{
std::vector<Reg> l;
std::vector<aReg> r;
l.reserve(N);
r.reserve(M);
for(int i = 0; i < N; i++) {
l.push_back(callbacks[i]);
}
for(int i = 0; i < M; i++) {
r.push_back(accessors[i]);
}
initialize(l, r);
}
plugins_context( const std::string & name, const reg_vec& callbacks, const areg_vec& accessors);

void play_slice();

Expand All @@ -74,7 +61,7 @@ class plugins_context {
typedef std::map<std::string, callback_function > callback_list;
typedef std::map<std::string, accessor_function > accessor_list;

void initialize(const std::vector<Reg>& callbacks, const std::vector<aReg>& accessors);
void initialize(const reg_vec& callbacks, const areg_vec& accessors);

callback_list callbacks_;
accessor_list accessors_;
Expand Down
4 changes: 2 additions & 2 deletions src/wesnoth.cpp
Expand Up @@ -790,11 +790,11 @@ static int do_gameloop(const std::vector<std::string>& args)

plugins_manager plugins_man(new application_lua_kernel);

plugins_context::Reg const callbacks[] {
const plugins_context::reg_vec callbacks {
{"play_multiplayer", std::bind(&game_launcher::play_multiplayer, game.get(), game_launcher::MP_CONNECT)},
};

plugins_context::aReg const accessors[] {
const plugins_context::areg_vec accessors {
{"command_line", std::bind(&commandline_options::to_config, &cmdline_opts)},
};

Expand Down

0 comments on commit 3c01a43

Please sign in to comment.