diff --git a/scripting/lua/LuaCallWrapper.h b/scripting/lua/LuaCallWrapper.h index c098116a3..2876102e3 100644 --- a/scripting/lua/LuaCallWrapper.h +++ b/scripting/lua/LuaCallWrapper.h @@ -12,6 +12,7 @@ #include "api/Registry.h" #include "LuaStack.h" +#include VCMI_LIB_NAMESPACE_BEGIN @@ -187,6 +188,7 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -196,7 +198,7 @@ public: if(!S.tryGet(1,obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); @@ -210,6 +212,7 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -219,7 +222,7 @@ public: if(!S.tryGet(1,obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); @@ -233,6 +236,7 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -242,7 +246,7 @@ public: if(!S.tryGet(1,obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); @@ -256,6 +260,7 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -265,7 +270,7 @@ public: if(!S.tryGet(1,obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); @@ -279,6 +284,8 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; + using PM2 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -288,11 +295,11 @@ public: if(!S.tryGet(1, obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); - P2 p2; + PM2 p2; if(!S.tryGet(3, p2)) return S.retVoid(); @@ -306,6 +313,8 @@ public: template class LuaMethodWrapper { + using PM1 = std::remove_cv_t>; + using PM2 = std::remove_cv_t>; public: static int invoke(lua_State * L) { @@ -315,11 +324,11 @@ public: if(!S.tryGet(1, obj)) return S.retVoid(); - P1 p1; + PM1 p1; if(!S.tryGet(2, p1)) return S.retVoid(); - P2 p2; + PM2 p2; if(!S.tryGet(3, p2)) return S.retVoid(); diff --git a/scripting/lua/LuaReference.cpp b/scripting/lua/LuaReference.cpp index a5b8c2f44..0e411c239 100644 --- a/scripting/lua/LuaReference.cpp +++ b/scripting/lua/LuaReference.cpp @@ -23,7 +23,7 @@ LuaReference::LuaReference(lua_State * L) key = luaL_ref(l, LUA_REGISTRYINDEX); } -LuaReference::LuaReference(LuaReference && other) +LuaReference::LuaReference(LuaReference && other) noexcept : l(other.l), key(other.key), doCleanup(false) diff --git a/scripting/lua/LuaReference.h b/scripting/lua/LuaReference.h index 22290aa55..e44512409 100644 --- a/scripting/lua/LuaReference.h +++ b/scripting/lua/LuaReference.h @@ -21,7 +21,7 @@ public: //pop from the top of stack LuaReference(lua_State * L); - LuaReference(LuaReference && other); + LuaReference(LuaReference && other) noexcept; ~LuaReference(); void push(); diff --git a/scripting/lua/LuaScriptingContext.cpp b/scripting/lua/LuaScriptingContext.cpp index bf27588ec..48e841c9f 100644 --- a/scripting/lua/LuaScriptingContext.cpp +++ b/scripting/lua/LuaScriptingContext.cpp @@ -34,13 +34,12 @@ namespace scripting const std::string LuaContext::STATE_FIELD = "DATA"; -LuaContext::LuaContext(const Script * source, const Environment * env_) - : ContextBase(env_->logger()), +LuaContext::LuaContext(const Script * source, const Environment * env_): + ContextBase(env_->logger()), + L(luaL_newstate()), script(source), env(env_) { - L = luaL_newstate(); - static const std::vector STD_LIBS = { {"", luaopen_base}, @@ -417,7 +416,7 @@ void LuaContext::popAll() std::string LuaContext::toStringRaw(int index) { size_t len = 0; - auto raw = lua_tolstring(L, index, &len); + const auto *raw = lua_tolstring(L, index, &len); return std::string(raw, len); } @@ -431,7 +430,7 @@ void LuaContext::registerCore() popAll();//just in case - for(auto & registar : api::Registry::get()->getCoreData()) + for(const auto & registar : api::Registry::get()->getCoreData()) { registar.second->pushMetatable(L); //table @@ -446,7 +445,7 @@ void LuaContext::registerCore() int LuaContext::require(lua_State * L) { - LuaContext * self = static_cast(lua_touserdata(L, lua_upvalueindex(1))); + auto * self = static_cast(lua_touserdata(L, lua_upvalueindex(1))); if(!self) { @@ -503,7 +502,7 @@ int LuaContext::loadModule() if(scope.empty()) { - auto registar = api::Registry::get()->find(modulePath); + const auto *registar = api::Registry::get()->find(modulePath); if(!registar) { @@ -519,7 +518,7 @@ int LuaContext::loadModule() boost::algorithm::replace_all(modulePath, ".", "/"); - auto loader = CResourceHandler::get(CModHandler::scopeBuiltin()); + auto *loader = CResourceHandler::get(CModHandler::scopeBuiltin()); modulePath = "scripts/lib/" + modulePath; @@ -582,7 +581,7 @@ int LuaContext::printImpl() int LuaContext::logError(lua_State * L) { - LuaContext * self = static_cast(lua_touserdata(L, lua_upvalueindex(1))); + auto * self = static_cast(lua_touserdata(L, lua_upvalueindex(1))); if(!self) { diff --git a/scripting/lua/LuaSpellEffect.cpp b/scripting/lua/LuaSpellEffect.cpp index e698e52eb..c039567f3 100644 --- a/scripting/lua/LuaSpellEffect.cpp +++ b/scripting/lua/LuaSpellEffect.cpp @@ -94,7 +94,7 @@ bool LuaSpellEffect::applicable(Problem & problem, const Mechanics * m, const Ef if(target.empty()) return false; - for(auto & dest : target) + for(const auto & dest : target) { JsonNode targetData; targetData.Vector().push_back(JsonUtils::intNode(dest.hexValue.hex)); @@ -137,7 +137,7 @@ void LuaSpellEffect::apply(ServerCallback * server, const Mechanics * m, const E JsonNode requestP; - for(auto & dest : target) + for(const auto & dest : target) { JsonNode targetData; targetData.Vector().push_back(JsonUtils::intNode(dest.hexValue.hex)); @@ -176,7 +176,7 @@ std::shared_ptr LuaSpellEffect::resolveScript(const Mechanics * m) cons return m->battle()->getContextPool()->getContext(script); } -void LuaSpellEffect::setContextVariables(const Mechanics * m, std::shared_ptr context) const +void LuaSpellEffect::setContextVariables(const Mechanics * m, const std::shared_ptr& context) { context->setGlobal("effectLevel", m->getEffectLevel()); context->setGlobal("effectRangeLevel", m->getRangeLevel()); diff --git a/scripting/lua/LuaSpellEffect.h b/scripting/lua/LuaSpellEffect.h index ead2ed3d0..effb620e7 100644 --- a/scripting/lua/LuaSpellEffect.h +++ b/scripting/lua/LuaSpellEffect.h @@ -68,7 +68,7 @@ private: std::shared_ptr resolveScript(const Mechanics * m) const; - void setContextVariables(const Mechanics * m, std::shared_ptr context) const; + static void setContextVariables(const Mechanics * m, const std::shared_ptr& context) ; }; } diff --git a/scripting/lua/LuaStack.cpp b/scripting/lua/LuaStack.cpp index 2734eea3b..18dc12803 100644 --- a/scripting/lua/LuaStack.cpp +++ b/scripting/lua/LuaStack.cpp @@ -19,10 +19,10 @@ VCMI_LIB_NAMESPACE_BEGIN namespace scripting { -LuaStack::LuaStack(lua_State * L_) - : L(L_) +LuaStack::LuaStack(lua_State * L_): + L(L_), + initialTop(lua_gettop(L)) { - initialTop = lua_gettop(L); } void LuaStack::balance() @@ -94,7 +94,7 @@ void LuaStack::push(const JsonNode & value) case JsonNode::JsonType::DATA_STRUCT: { lua_newtable(L); - for(auto & keyValue : value.Struct()) + for(const auto & keyValue : value.Struct()) { push(keyValue.first); push(keyValue.second); @@ -154,7 +154,7 @@ bool LuaStack::tryGet(int position, std::string & value) return false; size_t len = 0; - auto raw = lua_tolstring(L, position, &len); + const auto *raw = lua_tolstring(L, position, &len); value = std::string(raw, len); return true; diff --git a/scripting/lua/api/BonusSystem.cpp b/scripting/lua/api/BonusSystem.cpp index cb03f6481..312b335b3 100644 --- a/scripting/lua/api/BonusSystem.cpp +++ b/scripting/lua/api/BonusSystem.cpp @@ -159,7 +159,7 @@ static void publishMap(lua_State * L, const T & map) for(auto & p : map) { const std::string & name = p.first; - int32_t id = static_cast(p.second); + auto id = static_cast(p.second); lua_pushstring(L, name.c_str()); lua_pushinteger(L, id); diff --git a/scripting/lua/api/Registry.cpp b/scripting/lua/api/Registry.cpp index 5af09bc55..0b86a3d42 100644 --- a/scripting/lua/api/Registry.cpp +++ b/scripting/lua/api/Registry.cpp @@ -28,12 +28,12 @@ Registry * Registry::get() void Registry::add(const std::string & name, std::shared_ptr item) { - data[name] = item; + data[name] = std::move(item); } void Registry::addCore(const std::string & name, std::shared_ptr item) { - coreData[name] = item; + coreData[name] = std::move(item); } const Registar * Registry::find(const std::string & name) const diff --git a/scripting/lua/api/ServerCb.cpp b/scripting/lua/api/ServerCb.cpp index f448efb54..1d0f9d501 100644 --- a/scripting/lua/api/ServerCb.cpp +++ b/scripting/lua/api/ServerCb.cpp @@ -72,7 +72,7 @@ int ServerCbProxy::commitPackage(lua_State * L) return S.retVoid(); - CPackForClient * pack = static_cast(lua_touserdata(L, 1)); + auto * pack = static_cast(lua_touserdata(L, 1)); object->apply(pack); diff --git a/scripting/lua/api/netpacks/InfoWindow.cpp b/scripting/lua/api/netpacks/InfoWindow.cpp index 41899448c..1f0d7447e 100644 --- a/scripting/lua/api/netpacks/InfoWindow.cpp +++ b/scripting/lua/api/netpacks/InfoWindow.cpp @@ -53,7 +53,7 @@ int InfoWindowProxy::addReplacement(lua_State * L) if(lua_isstring(L, 2)) { size_t len = 0; - auto raw = lua_tolstring(L, 2, &len); + const auto *raw = lua_tolstring(L, 2, &len); std::string text(raw, len); object->text.addReplacement(text); @@ -87,7 +87,7 @@ int InfoWindowProxy::addText(lua_State * L) if(lua_isstring(L, 2)) { size_t len = 0; - auto raw = lua_tolstring(L, 2, &len); + const auto *raw = lua_tolstring(L, 2, &len); std::string text(raw, len); object->text << text;