diff --git a/include/Nazara/Core/ParameterList.hpp b/include/Nazara/Core/ParameterList.hpp index 75972b49c..3e9d3a825 100644 --- a/include/Nazara/Core/ParameterList.hpp +++ b/include/Nazara/Core/ParameterList.hpp @@ -27,6 +27,9 @@ namespace Nz void Clear(); + inline void ForEach(const std::function& callback); + inline void ForEach(const std::function& callback) const; + bool GetBooleanParameter(const String& name, bool* value) const; bool GetColorParameter(const String& name, Color* value) const; bool GetFloatParameter(const String& name, float* value) const; @@ -102,4 +105,6 @@ namespace Nz std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList); +#include + #endif // NAZARA_PARAMETERLIST_HPP diff --git a/include/Nazara/Core/ParameterList.inl b/include/Nazara/Core/ParameterList.inl new file mode 100644 index 000000000..b1983b49b --- /dev/null +++ b/include/Nazara/Core/ParameterList.inl @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + /*! + * \brief Iterates over every value of the parameter list + * + * \param callback Callback function called with every parameter contained in the list, which can return true to remove the key (or false to keep it) + * + * \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe. + */ + inline void ParameterList::ForEach(const std::function& callback) + { + for (auto it = m_parameters.begin(); it != m_parameters.end();) + { + if (callback(*this, it->first)) + it = m_parameters.erase(it); + else + ++it; + } + } + + /*! + * \brief Iterates over every value of the parameter list + * + * \param callback Callback function called with every parameter contained in the list + * + * \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe. + */ + inline void ParameterList::ForEach(const std::function& callback) const + { + for (auto& pair : m_parameters) + callback(*this, pair.first); + } +} + +#include diff --git a/include/Nazara/Lua/LuaInstance.hpp b/include/Nazara/Lua/LuaInstance.hpp index 39b0879a8..2ac752c9e 100644 --- a/include/Nazara/Lua/LuaInstance.hpp +++ b/include/Nazara/Lua/LuaInstance.hpp @@ -101,6 +101,7 @@ namespace Nz bool GetMetatable(int index) const; unsigned int GetStackTop() const; LuaType GetTable(int index = -2) const; + LuaType GetTableRaw(int index = -2) const; inline UInt32 GetTimeLimit() const; LuaType GetType(int index) const; const char* GetTypeName(LuaType type) const; @@ -113,6 +114,7 @@ namespace Nz bool IsValid(int index) const; long long Length(int index) const; + std::size_t LengthRaw(int index) const; void MoveTo(LuaInstance* instance, int n) const; @@ -161,6 +163,7 @@ namespace Nz void SetMetatable(int index) const; void SetMemoryLimit(std::size_t memoryLimit); void SetTable(int index = -3) const; + void SetTableRaw(int index = -3) const; void SetTimeLimit(UInt32 timeLimit); bool ToBoolean(int index) const; diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp index 380e7c48f..1c8f25567 100644 --- a/src/Nazara/Lua/LuaInstance.cpp +++ b/src/Nazara/Lua/LuaInstance.cpp @@ -503,6 +503,11 @@ namespace Nz return FromLuaType(lua_gettable(m_state, index)); } + LuaType LuaInstance::GetTableRaw(int index) const + { + return FromLuaType(lua_rawget(m_state, index)); + } + LuaType LuaInstance::GetType(int index) const { return FromLuaType(lua_type(m_state, index)); @@ -586,6 +591,11 @@ namespace Nz return luaL_len(m_state, index); } + std::size_t LuaInstance::LengthRaw(int index) const + { + return lua_rawlen(m_state, index); + } + void LuaInstance::MoveTo(LuaInstance* instance, int n) const { lua_xmove(m_state, instance->m_state, n); @@ -750,6 +760,11 @@ namespace Nz lua_settable(m_state, index); } + void LuaInstance::SetTableRaw(int index) const + { + lua_rawset(m_state, index); + } + void LuaInstance::SetTimeLimit(UInt32 timeLimit) { if (m_timeLimit != timeLimit)