summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/BindingsProcessor.lua12
-rw-r--r--src/Bindings/CMakeLists.txt9
-rw-r--r--src/Bindings/LuaChunkStay.cpp6
-rw-r--r--src/Bindings/LuaState.cpp51
-rw-r--r--src/Bindings/LuaState.h54
-rw-r--r--src/Bindings/ManualBindings.cpp4
-rw-r--r--src/Bindings/ManualBindings.h12
-rw-r--r--src/Bindings/ManualBindings_Network.cpp7
-rw-r--r--src/Bindings/ManualBindings_World.cpp5
-rw-r--r--src/Bindings/PluginLua.cpp10
-rw-r--r--src/Bindings/PluginManager.cpp2
11 files changed, 92 insertions, 80 deletions
diff --git a/src/Bindings/BindingsProcessor.lua b/src/Bindings/BindingsProcessor.lua
index f86be6c6d..fba992082 100644
--- a/src/Bindings/BindingsProcessor.lua
+++ b/src/Bindings/BindingsProcessor.lua
@@ -101,7 +101,7 @@ local function OutputLuaStateHelpers(a_Package)
f:write("void Push(" .. item.name .. " * a_Value);\n")
end
for _, item in ipairs(types) do
- f:write("void GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n")
+ f:write("bool GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n")
end
f:write("\n\n\n\n\n")
f:close()
@@ -125,15 +125,17 @@ local function OutputLuaStateHelpers(a_Package)
end
end
for _, item in ipairs(types) do
- f:write("void cLuaState::GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n")
+ f:write("bool cLuaState::GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n")
f:write("\tif (lua_isnil(m_LuaState, a_StackPos))\n\t{\n")
- f:write("\t a_ReturnedVal = nullptr;\n")
- f:write("\t return;\n\t}\n")
+ f:write("\t\ta_ReturnedVal = nullptr;\n")
+ f:write("\t\treturn false;\n\t}\n")
f:write("\ttolua_Error err;\n")
f:write("\tif (tolua_isusertype(m_LuaState, a_StackPos, \"" .. item.name .. "\", false, &err))\n")
f:write("\t{\n")
- f:write("\t a_ReturnedVal = *(reinterpret_cast<" .. item.name .. " **>(lua_touserdata(m_LuaState, a_StackPos)));\n")
+ f:write("\t\ta_ReturnedVal = *(reinterpret_cast<" .. item.name .. " **>(lua_touserdata(m_LuaState, a_StackPos)));\n")
+ f:write("\t\treturn true;\n");
f:write("\t}\n")
+ f:write("\treturn false;\n")
f:write("}\n\n\n\n\n\n")
end
f:close()
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index 133c2224d..0a069ad85 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -145,6 +145,15 @@ set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error)
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ set_source_files_properties(DeprecatedBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast")
+ set_source_files_properties(LuaState.cpp COMPILE_FLAGS "-Wno-error=old-style-cast")
+ set_source_files_properties(LuaWindow.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum")
+ set_source_files_properties(ManualBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast")
+ set_source_files_properties(ManualBindings_World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast")
+ set_source_files_properties(PluginLua.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast")
+endif()
+
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp
index e50ffb75b..1afd09d11 100644
--- a/src/Bindings/LuaChunkStay.cpp
+++ b/src/Bindings/LuaChunkStay.cpp
@@ -41,7 +41,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos)
// Add each set of coords:
int NumChunks = luaL_getn(L, a_ChunkCoordTableStackPos);
- m_Chunks.reserve((size_t)NumChunks);
+ m_Chunks.reserve(static_cast<size_t>(NumChunks));
for (int idx = 1; idx <= NumChunks; idx++)
{
// Push the idx-th element of the array onto stack top, check that it's a table:
@@ -133,7 +133,7 @@ void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
if (m_OnChunkAvailable.IsValid())
{
cPluginLua::cOperation Op(m_Plugin);
- Op().Call((int)m_OnChunkAvailable, a_ChunkX, a_ChunkZ);
+ Op().Call(static_cast<int>(m_OnChunkAvailable), a_ChunkX, a_ChunkZ);
}
}
@@ -147,7 +147,7 @@ bool cLuaChunkStay::OnAllChunksAvailable(void)
{
// Call the callback:
cPluginLua::cOperation Op(m_Plugin);
- Op().Call((int)m_OnAllChunksAvailable);
+ Op().Call(static_cast<int>(m_OnAllChunksAvailable));
// Remove the callback references - they won't be needed anymore
m_OnChunkAvailable.UnRef();
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 08c7e19d7..232432a99 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -701,108 +701,95 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type)
-void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
+bool cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
size_t len = 0;
const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
if (data != nullptr)
{
a_Value.assign(data, len);
+ return true;
}
+ return false;
}
-void cLuaState::GetStackValue(int a_StackPos, BLOCKTYPE & a_ReturnedVal)
-{
- if (lua_isnumber(m_LuaState, a_StackPos))
- {
- a_ReturnedVal = static_cast<BLOCKTYPE>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal));
- }
-}
-
-
-
-
-
-void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
+bool cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
+ return true;
}
-void cLuaState::GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result)
+bool cLuaState::GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
a_Result = static_cast<cPluginManager::CommandResult>(static_cast<int>((tolua_tonumber(m_LuaState, a_StackPos, a_Result))));
+ return true;
}
+ return false;
}
-void cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref)
+bool cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref)
{
a_Ref.RefStack(*this, a_StackPos);
+ return true;
}
-void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
+bool cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
a_ReturnedVal = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
+ return true;
}
+ return false;
}
-void cLuaState::GetStackValue(int a_StackPos, float & a_ReturnedVal)
+bool cLuaState::GetStackValue(int a_StackPos, float & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
a_ReturnedVal = static_cast<float>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal));
+ return true;
}
+ return false;
}
-void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal)
+bool cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal)
{
if (!lua_isnumber(m_LuaState, a_StackPos))
{
- return;
+ return false;
}
a_ReturnedVal = static_cast<eWeather>(Clamp(
static_cast<int>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)),
static_cast<int>(wSunny), static_cast<int>(wThunderstorm))
);
-}
-
-
-
-
-
-void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
-{
- if (lua_isnumber(m_LuaState, a_StackPos))
- {
- a_ReturnedVal = static_cast<int>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal));
- }
+ return true;
}
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 5b4ec3ae4..8a3411d30 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -187,16 +187,37 @@ public:
void Push(cLuaUDPEndpoint * a_UDPEndpoint);
// GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged.
+ // Returns whether value was changed
// Enum values are clamped to their allowed range.
- void GetStackValue(int a_StackPos, AString & a_Value);
- void GetStackValue(int a_StackPos, BLOCKTYPE & a_Value);
- void GetStackValue(int a_StackPos, bool & a_Value);
- void GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result);
- void GetStackValue(int a_StackPos, cRef & a_Ref);
- void GetStackValue(int a_StackPos, double & a_Value);
- void GetStackValue(int a_StackPos, eWeather & a_Value);
- void GetStackValue(int a_StackPos, float & a_ReturnedVal);
- void GetStackValue(int a_StackPos, int & a_Value);
+ bool GetStackValue(int a_StackPos, AString & a_Value);
+ bool GetStackValue(int a_StackPos, bool & a_Value);
+ bool GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result);
+ bool GetStackValue(int a_StackPos, cRef & a_Ref);
+ bool GetStackValue(int a_StackPos, double & a_Value);
+ bool GetStackValue(int a_StackPos, eWeather & a_Value);
+ bool GetStackValue(int a_StackPos, float & a_ReturnedVal);
+
+ // template to catch all of the various c++ integral types without overload conflicts
+ template <class T>
+ bool GetStackValue(int a_StackPos, T & a_ReturnedVal, typename std::enable_if<std::is_integral<T>::value>::type * unused = nullptr)
+ {
+ UNUSED(unused);
+ if (lua_isnumber(m_LuaState, a_StackPos))
+ {
+ lua_Number Val = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
+ if (Val > std::numeric_limits<T>::max())
+ {
+ return false;
+ }
+ if (Val < std::numeric_limits<T>::min())
+ {
+ return false;
+ }
+ a_ReturnedVal = static_cast<T>(Val);
+ return true;
+ }
+ return false;
+ }
// Include the auto-generated Push and GetStackValue() functions:
#include "LuaState_Declaration.inc"
@@ -218,10 +239,13 @@ public:
/** Retrieves a list of values from the Lua stack, starting at the specified index. */
template <typename T, typename... Args>
- inline void GetStackValues(int a_StartStackPos, T & a_Ret, Args &&... args)
+ inline bool GetStackValues(int a_StartStackPos, T & a_Ret, Args &&... args)
{
- GetStackValue(a_StartStackPos, a_Ret);
- GetStackValues(a_StartStackPos + 1, args...);
+ if (!GetStackValue(a_StartStackPos, a_Ret))
+ {
+ return false;
+ }
+ return GetStackValues(a_StartStackPos + 1, args...);
}
/** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */
@@ -349,9 +373,9 @@ protected:
/** Variadic template terminator: If there are no more values to get, bail out.
This function is not available in the public API, because it's an error to request no values directly; only internal functions can do that.
If you get a compile error saying this function is not accessible, check your calling code, you aren't reading any stack values. */
- void GetStackValues(int a_StartingStackPos)
+ bool GetStackValues(int a_StartingStackPos)
{
- // Do nothing
+ return true;
}
/** Pushes the function of the specified name onto the stack.
@@ -369,7 +393,7 @@ protected:
*/
bool PushFunction(const cRef & a_FnRef)
{
- return PushFunction((int)a_FnRef);
+ return PushFunction(static_cast<int>(a_FnRef));
}
/** Pushes a function that is stored in a referenced table by name
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index ff904d74a..bce1891e2 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -158,7 +158,7 @@ static int tolua_UncompressStringZLIB(lua_State * tolua_S)
// Get the params:
AString ToUncompress;
- int UncompressedSize;
+ size_t UncompressedSize;
S.GetStackValues(1, ToUncompress, UncompressedSize);
// Compress the string:
@@ -1801,7 +1801,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
// Convert the input table into AStringVector:
AStringVector PlayerNames;
int NumNames = luaL_getn(L, 2);
- PlayerNames.reserve(NumNames);
+ PlayerNames.reserve(static_cast<size_t>(NumNames));
for (int i = 1; i <= NumNames; i++)
{
lua_rawgeti(L, 2, i);
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index e7a576588..f8c9b96de 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -199,7 +199,7 @@ public:
// Get parameters:
Ty1 * Self = nullptr;
- int ItemID;
+ UInt32 ItemID;
cLuaState::cRef FnRef;
L.GetStackValues(1, Self, ItemID, FnRef);
if (Self == nullptr)
@@ -253,8 +253,9 @@ public:
// Check params:
cLuaState L(tolua_S);
if (
- !L.CheckParamNumber(2, 5) ||
- !L.CheckParamFunction(6)
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamFunction(5) ||
+ !L.CheckParamEnd(6)
)
{
return 0;
@@ -316,8 +317,9 @@ public:
// Check params:
cLuaState L(tolua_S);
if (
- !L.CheckParamNumber(2, 4) ||
- !L.CheckParamFunction(5)
+ !L.CheckParamNumber(2, 3) ||
+ !L.CheckParamFunction(4) ||
+ !L.CheckParamEnd(5)
)
{
return 0;
diff --git a/src/Bindings/ManualBindings_Network.cpp b/src/Bindings/ManualBindings_Network.cpp
index df97d60b3..b5fb5b046 100644
--- a/src/Bindings/ManualBindings_Network.cpp
+++ b/src/Bindings/ManualBindings_Network.cpp
@@ -101,13 +101,12 @@ static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L)
}
// Read the params:
- int Port;
- S.GetStackValues(2, Port);
+ UInt16 Port;
// Check validity:
- if ((Port < 0) || (Port > 65535))
+ if (!S.GetStackValues(2, Port))
{
- LOGWARNING("cNetwork:CreateUDPEndpoint() called with invalid port (%d), failing the request.", Port);
+ LOGWARNING("cNetwork:CreateUDPEndpoint() called with invalid port, failing the request.");
S.Push(false);
return 1;
}
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
index 5becbba92..ddbebce78 100644
--- a/src/Bindings/ManualBindings_World.cpp
+++ b/src/Bindings/ManualBindings_World.cpp
@@ -50,7 +50,7 @@ static int tolua_cWorld_BroadcastParticleEffect(lua_State * tolua_S)
std::array<int, 2> data;
for (int i = 0; (i < 2) && L.IsParamNumber(11 + i); i++)
{
- L.GetStackValue(11 + i, data[i]);
+ L.GetStackValue(11 + i, data[static_cast<size_t>(i)]);
}
World->GetBroadcaster().BroadcastParticleEffect(Name, Vector3f(PosX, PosY, PosZ), Vector3f(OffX, OffY, OffZ), ParticleData, ParticleAmmount, ExcludeClient);
@@ -303,10 +303,9 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S)
cLuaState m_LuaState;
cLuaState::cRef m_Callback;
};
- cCallback * callback = new cCallback(tolua_S);
// Call the chunk preparation:
- world->PrepareChunk(chunkX, chunkZ, callback);
+ world->PrepareChunk(chunkX, chunkZ, cpp14::make_unique<cCallback>(tolua_S));
return 0;
}
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 234bf579b..d3ffcd0f4 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -629,11 +629,6 @@ bool cPluginLua::OnExploded(cWorld & a_World, double a_ExplosionSize, bool a_Can
case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
- default:
- {
- ASSERT(!"Unhandled ExplosionSource");
- return false;
- }
}
if (res)
{
@@ -670,11 +665,6 @@ bool cPluginLua::OnExploding(cWorld & a_World, double & a_ExplosionSize, bool &
case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
- default:
- {
- ASSERT(!"Unhandled ExplosionSource");
- return false;
- }
}
if (res)
{
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 4dc3e20d3..5b6bec728 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -1935,7 +1935,7 @@ size_t cPluginManager::GetNumLoadedPlugins(void) const
AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_Settings)
{
// Check if the Plugins section exists.
- if (a_Settings.KeyExists("Plugins"))
+ if (!a_Settings.KeyExists("Plugins"))
{
InsertDefaultPlugins(a_Settings);
}