From 7fc1d0317a7b16ed4ee62fca5290961c9f56500f Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 19 Jan 2021 17:08:40 +1100 Subject: [PATCH] AI/Lua Object: minor code cleanup --- src/ai/lua/lua_object.hpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ai/lua/lua_object.hpp b/src/ai/lua/lua_object.hpp index b14148de693c..c028b14ae649 100644 --- a/src/ai/lua/lua_object.hpp +++ b/src/ai/lua/lua_object.hpp @@ -138,7 +138,7 @@ inline std::shared_ptr< utils::variant> > lua_obj if (lua_isboolean(L, n)) { return std::make_shared>>(luaW_toboolean(L, n)); } else { - std::shared_ptr> v(new std::vector()); + auto v = std::make_shared>(); int l = lua_rawlen(L, n); for (int i = 1; i < l + 1; ++i) { @@ -189,7 +189,7 @@ inline void lua_object::from_type(lua_State *L, std::shared_ptr value) template <> inline std::shared_ptr< std::vector > lua_object< std::vector >::to_type(lua_State *L, int n) { - std::shared_ptr> v(new std::vector()); + auto v = std::make_shared>(); int l = lua_rawlen(L, n); for (int i = 1; i < l + 1; ++i) { @@ -218,7 +218,7 @@ inline void lua_object< std::vector >::from_type(lua_State *L, std: template <> inline std::shared_ptr lua_object::to_type(lua_State *L, int n) { - std::shared_ptr cfg(new config()); + auto cfg = std::make_shared(); luaW_toconfig(L, n, *cfg); return cfg; } @@ -233,14 +233,13 @@ inline void lua_object::from_type(lua_State *L, std::shared_ptr template <> inline std::shared_ptr lua_object::to_type(lua_State *L, int n) { - std::shared_ptr cfg(new config()); - std::shared_ptr vcfg(new vconfig(*cfg)); + auto cfg = std::make_shared(); + auto vcfg = std::make_shared(*cfg); if (!luaW_tovconfig(L, n, *vcfg)) { cfg->add_child("not"); } vcfg->make_safe(); - std::shared_ptr tf(new terrain_filter(*vcfg, resources::filter_con, false)); - return tf; + return std::make_shared(*vcfg, resources::filter_con, false); } template <> @@ -260,8 +259,7 @@ inline void lua_object::from_type(lua_State *L, std::shared_ptr< template <> inline std::shared_ptr > lua_object< std::vector >::to_type(lua_State *L, int n) { - std::shared_ptr> targets(new std::vector()); - std::back_insert_iterator< std::vector > tg(*targets); + auto targets = std::make_shared>(); int l = lua_rawlen(L, n); for (int i = 1; i <= l; ++i) @@ -298,7 +296,7 @@ inline std::shared_ptr > lua_object< std::vector >:: map_location ml(x, y, wml_loc()); - *tg = target(ml, value, type); + targets->emplace_back(ml, value, type); } lua_settop(L, n);