From 360c632e36acfe8b271c3212feef9b6f93623ba1 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 28 Jan 2015 15:14:05 +0100 Subject: cNetwork: Exported the Connect() method and cTCPLink class to Lua. --- src/Bindings/ManualBindings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 56f2e73bc..24e3f0052 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -256,7 +256,7 @@ static int tolua_Base64Decode(lua_State * tolua_S) -static cPluginLua * GetLuaPlugin(lua_State * L) +cPluginLua * GetLuaPlugin(lua_State * L) { // Get the plugin identification out of LuaState: lua_getglobal(L, LUA_PLUGIN_INSTANCE_VAR_NAME); @@ -3556,6 +3556,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "md5", tolua_md5); BindRankManager(tolua_S); + BindNetwork(tolua_S); tolua_endmodule(tolua_S); } -- cgit v1.2.3 From 5d4dd103a12a44c8482d524c38841221da1d8fb2 Mon Sep 17 00:00:00 2001 From: Matyas Dolak Date: Fri, 20 Feb 2015 09:51:18 +0100 Subject: Fixed crash when logging nil values. Ref.: http://forum.mc-server.org/showthread.php?tid=1798 --- src/Bindings/ManualBindings.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 24e3f0052..30bce6525 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -165,6 +165,14 @@ static AString GetLogMessage(lua_State * tolua_S) static int tolua_LOG(lua_State * tolua_S) { + // If there's no param, spit out an error message instead of crashing: + if (lua_isnil(tolua_S, 1)) + { + LOGWARNING("Attempting to LOG a nil value!"); + cLuaState::LogStackTrace(tolua_S); + return 0; + } + // If the param is a cCompositeChat, read the log level from it: cLogger::eLogLevel LogLevel = cLogger::llRegular; tolua_Error err; @@ -184,6 +192,14 @@ static int tolua_LOG(lua_State * tolua_S) static int tolua_LOGINFO(lua_State * tolua_S) { + // If there's no param, spit out an error message instead of crashing: + if (lua_isnil(tolua_S, 1)) + { + LOGWARNING("Attempting to LOGINFO a nil value!"); + cLuaState::LogStackTrace(tolua_S); + return 0; + } + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llInfo); return 0; } @@ -194,6 +210,14 @@ static int tolua_LOGINFO(lua_State * tolua_S) static int tolua_LOGWARN(lua_State * tolua_S) { + // If there's no param, spit out an error message instead of crashing: + if (lua_isnil(tolua_S, 1)) + { + LOGWARNING("Attempting to LOGWARN a nil value!"); + cLuaState::LogStackTrace(tolua_S); + return 0; + } + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llWarning); return 0; } @@ -204,6 +228,14 @@ static int tolua_LOGWARN(lua_State * tolua_S) static int tolua_LOGERROR(lua_State * tolua_S) { + // If there's no param, spit out an error message instead of crashing: + if (lua_isnil(tolua_S, 1)) + { + LOGWARNING("Attempting to LOGERROR a nil value!"); + cLuaState::LogStackTrace(tolua_S); + return 0; + } + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llError); return 0; } -- cgit v1.2.3 From b9e4fe0a3b2a6a4d688d1a0807f15944361fb585 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 21 Feb 2015 09:41:14 +0100 Subject: Added cCryptoHash namespace to Lua API. --- src/Bindings/ManualBindings.cpp | 109 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 30bce6525..69d16ac2b 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3,8 +3,11 @@ #include "ManualBindings.h" #undef TOLUA_TEMPLATE_BIND +#include +#include #include "tolua++/include/tolua++.h" #include "polarssl/md5.h" +#include "polarssl/sha1.h" #include "PluginLua.h" #include "PluginManager.h" #include "LuaWindow.h" @@ -2203,11 +2206,16 @@ static int tolua_cPlugin_Call(lua_State * tolua_S) -static int tolua_md5(lua_State* tolua_S) +static int tolua_md5(lua_State * tolua_S) { + // Calculate the raw md5 checksum byte array: unsigned char Output[16]; size_t len = 0; const unsigned char * SourceString = (const unsigned char *)lua_tolstring(tolua_S, 1, &len); + if (SourceString == nullptr) + { + return 0; + } md5(SourceString, len, Output); lua_pushlstring(tolua_S, (const char *)Output, ARRAYCOUNT(Output)); return 1; @@ -2217,6 +2225,91 @@ static int tolua_md5(lua_State* tolua_S) +/** Does the same as tolua_md5, but reports that the usage is obsolete and the plugin should use cCrypto.md5(). */ +static int tolua_md5_obsolete(lua_State * tolua_S) +{ + LOGWARNING("Using md5() is obsolete, please change your plugin to use cCryptoHash.md5()"); + cLuaState::LogStackTrace(tolua_S); + return tolua_md5(tolua_S); +} + + + + + +static int tolua_md5HexString(lua_State * tolua_S) +{ + // Calculate the raw md5 checksum byte array: + unsigned char md5Output[16]; + size_t len = 0; + const unsigned char * SourceString = (const unsigned char *)lua_tolstring(tolua_S, 1, &len); + if (SourceString == nullptr) + { + return 0; + } + md5(SourceString, len, md5Output); + + // Convert the md5 checksum to hex string: + std::stringstream Output; + Output << std::hex << std::setw(2) << std::setfill('0'); + for (size_t i = 0; i < ARRAYCOUNT(md5Output); i++) + { + Output << static_cast(md5Output[i]); // Need to cast to a number, otherwise a char is output + } + lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size()); + return 1; +} + + + + + +static int tolua_sha1(lua_State * tolua_S) +{ + // Calculate the raw SHA1 checksum byte array from the input string: + unsigned char Output[20]; + size_t len = 0; + const unsigned char * SourceString = (const unsigned char *)lua_tolstring(tolua_S, 1, &len); + if (SourceString == nullptr) + { + return 0; + } + sha1(SourceString, len, Output); + lua_pushlstring(tolua_S, (const char *)Output, ARRAYCOUNT(Output)); + return 1; +} + + + + + +static int tolua_sha1HexString(lua_State * tolua_S) +{ + // Calculate the raw SHA1 checksum byte array from the input string: + unsigned char sha1Output[20]; + size_t len = 0; + const unsigned char * SourceString = (const unsigned char *)lua_tolstring(tolua_S, 1, &len); + if (SourceString == nullptr) + { + return 0; + } + sha1(SourceString, len, sha1Output); + + // Convert the sha1 checksum to hex string: + std::stringstream Output; + Output << std::hex << std::setw(2) << std::setfill('0'); + for (size_t i = 0; i < ARRAYCOUNT(sha1Output); i++) + { + Output << static_cast(sha1Output[i]); // Need to cast to a number, otherwise a char is output + } + lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size()); + return 1; +} + + + + + static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, std::string >& a_StringStringMap) { lua_newtable(tolua_S); @@ -3419,6 +3512,12 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, nullptr); + + // Create the new classes: + tolua_usertype(tolua_S, "cCryptoHash"); + tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr); + + // Globals: tolua_function(tolua_S, "Clamp", tolua_Clamp); tolua_function(tolua_S, "StringSplit", tolua_StringSplit); tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim); @@ -3429,6 +3528,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "LOGERROR", tolua_LOGERROR); tolua_function(tolua_S, "Base64Encode", tolua_Base64Encode); tolua_function(tolua_S, "Base64Decode", tolua_Base64Decode); + tolua_function(tolua_S, "md5", tolua_md5_obsolete); // OBSOLETE, use cCryptoHash.md5() instead tolua_beginmodule(tolua_S, "cFile"); tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents); @@ -3585,7 +3685,12 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords); tolua_endmodule(tolua_S); - tolua_function(tolua_S, "md5", tolua_md5); + tolua_beginmodule(tolua_S, "cCryptoHash"); + tolua_function(tolua_S, "md5", tolua_md5); + tolua_function(tolua_S, "md5HexString", tolua_md5HexString); + tolua_function(tolua_S, "sha1", tolua_sha1); + tolua_function(tolua_S, "sha1HexString", tolua_sha1HexString); + tolua_endmodule(tolua_S); BindRankManager(tolua_S); BindNetwork(tolua_S); -- cgit v1.2.3 From 13f81a051d948fd5acb278c5d8679efa5fb3297c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 22 Feb 2015 17:34:20 +0100 Subject: Exported CompressString and UncompressString to Lua --- src/Bindings/ManualBindings.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 69d16ac2b..ee3d81014 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -31,6 +31,7 @@ #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" #include "../CompositeChat.h" +#include "../StringCompression.h" @@ -110,6 +111,40 @@ static int tolua_Clamp(lua_State * tolua_S) +static int tolua_CompressString(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + const char * ToCompress = tolua_tocppstring(LuaState, 1, 0); + int Length = (int)tolua_tonumber(LuaState, 2, 0); + int Factor = (int)tolua_tonumber(LuaState, 3, 0); + AString res; + + CompressString(ToCompress, Length, res, Factor); + LuaState.Push(res); + return 1; +} + + + + + +static int tolua_UncompressString(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + const char * ToUncompress = tolua_tocppstring(LuaState, 1, 0); + int Length = (int)tolua_tonumber(LuaState, 2, 0); + int UncompressedSize = (int)tolua_tonumber(LuaState, 3, 0); + AString res; + + UncompressString(ToUncompress, Length, res, UncompressedSize); + LuaState.Push(res); + return 1; +} + + + + + static int tolua_StringSplit(lua_State * tolua_S) { cLuaState LuaState(tolua_S); @@ -3519,6 +3554,8 @@ void ManualBindings::Bind(lua_State * tolua_S) // Globals: tolua_function(tolua_S, "Clamp", tolua_Clamp); + tolua_function(tolua_S, "CompressString", tolua_CompressString); + tolua_function(tolua_S, "UncompressString", tolua_UncompressString); tolua_function(tolua_S, "StringSplit", tolua_StringSplit); tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim); tolua_function(tolua_S, "LOG", tolua_LOG); -- cgit v1.2.3 From 54410bfe4dac8793d6b46df725c400f7ce8d365e Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 23 Feb 2015 12:53:02 +0100 Subject: Exported all compression functions in a new class. --- src/Bindings/ManualBindings.cpp | 145 +++++++++++++++++++++++++++++++++++----- 1 file changed, 129 insertions(+), 16 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index ee3d81014..451161d87 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -111,16 +111,58 @@ static int tolua_Clamp(lua_State * tolua_S) -static int tolua_CompressString(lua_State * tolua_S) +static int tolua_CompressStringZLIB(lua_State * tolua_S) { - cLuaState LuaState(tolua_S); - const char * ToCompress = tolua_tocppstring(LuaState, 1, 0); - int Length = (int)tolua_tonumber(LuaState, 2, 0); - int Factor = (int)tolua_tonumber(LuaState, 3, 0); + cLuaState S(tolua_S); + if ( + !lua_isstring(tolua_S, 1) || + ( + !lua_isnumber(tolua_S, 2) && + !lua_isnil(tolua_S, 2) + ) + ) + { + cLuaState::LogStackTrace(tolua_S); + return 0; + } + + // Get the params: + AString ToCompress; + int CompressionLevel = 5; + S.GetStackValues(1, ToCompress, CompressionLevel); + + // Compress the string: AString res; + CompressString(ToCompress.data(), ToCompress.size(), res, CompressionLevel); + S.Push(res); + return 1; +} + + - CompressString(ToCompress, Length, res, Factor); - LuaState.Push(res); + + +static int tolua_UncompressStringZLIB(lua_State * tolua_S) +{ + cLuaState S(tolua_S); + if ( + !lua_isstring(tolua_S, 1) || + !lua_isnumber(tolua_S, 2) + ) + { + cLuaState::LogStackTrace(tolua_S); + return 0; + } + + // Get the params: + AString ToUncompress; + int UncompressedSize; + S.GetStackValues(1, ToUncompress, UncompressedSize); + + // Compress the string: + AString res; + UncompressString(ToUncompress.data(), ToUncompress.size(), res, UncompressedSize); + S.Push(res); return 1; } @@ -128,16 +170,79 @@ static int tolua_CompressString(lua_State * tolua_S) -static int tolua_UncompressString(lua_State * tolua_S) +static int tolua_CompressStringGZIP(lua_State * tolua_S) { - cLuaState LuaState(tolua_S); - const char * ToUncompress = tolua_tocppstring(LuaState, 1, 0); - int Length = (int)tolua_tonumber(LuaState, 2, 0); - int UncompressedSize = (int)tolua_tonumber(LuaState, 3, 0); + cLuaState S(tolua_S); + if (!lua_isstring(tolua_S, 1)) + { + cLuaState::LogStackTrace(tolua_S); + return 0; + } + + // Get the params: + AString ToCompress; + S.GetStackValues(1, ToCompress); + + // Compress the string: + AString res; + CompressStringGZIP(ToCompress.data(), ToCompress.size(), res); + S.Push(res); + return 1; +} + + + + + +static int tolua_UncompressStringGZIP(lua_State * tolua_S) +{ + cLuaState S(tolua_S); + if ( + !lua_isstring(tolua_S, 1) + ) + { + cLuaState::LogStackTrace(tolua_S); + return 0; + } + + + + // Get the params: + AString ToUncompress; + S.GetStackValues(1, ToUncompress); + + // Compress the string: AString res; + UncompressStringGZIP(ToUncompress.data(), ToUncompress.size(), res); + S.Push(res); + return 1; +} - UncompressString(ToUncompress, Length, res, UncompressedSize); - LuaState.Push(res); + + + + +static int tolua_InflateString(lua_State * tolua_S) +{ + cLuaState S(tolua_S); + if ( + !lua_isstring(tolua_S, 1) + ) + { + cLuaState::LogStackTrace(tolua_S); + return 0; + } + + + + // Get the params: + AString ToUncompress; + S.GetStackValues(1, ToUncompress); + + // Compress the string: + AString res; + InflateString(ToUncompress.data(), ToUncompress.size(), res); + S.Push(res); return 1; } @@ -3551,11 +3656,11 @@ void ManualBindings::Bind(lua_State * tolua_S) // Create the new classes: tolua_usertype(tolua_S, "cCryptoHash"); tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr); + tolua_usertype(tolua_S, "cStringCompression"); + tolua_cclass(tolua_S, "cStringCompression", "cStringCompression", "", nullptr); // Globals: tolua_function(tolua_S, "Clamp", tolua_Clamp); - tolua_function(tolua_S, "CompressString", tolua_CompressString); - tolua_function(tolua_S, "UncompressString", tolua_UncompressString); tolua_function(tolua_S, "StringSplit", tolua_StringSplit); tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim); tolua_function(tolua_S, "LOG", tolua_LOG); @@ -3729,6 +3834,14 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "sha1HexString", tolua_sha1HexString); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cStringCompression"); + tolua_function(tolua_S, "CompressStringZLIB", tolua_CompressStringZLIB); + tolua_function(tolua_S, "UncompressStringZLIB", tolua_UncompressStringZLIB); + tolua_function(tolua_S, "CompressStringGZIP", tolua_CompressStringGZIP); + tolua_function(tolua_S, "UncompressStringGZIP", tolua_UncompressStringGZIP); + tolua_function(tolua_S, "InflateString", tolua_InflateString); + tolua_endmodule(tolua_S); + BindRankManager(tolua_S); BindNetwork(tolua_S); -- cgit v1.2.3 From 8c8ec1094d8ba6df410f1fb0d0fba216b98a8f9a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 23 Feb 2015 15:29:07 +0100 Subject: Replaced lua_isXYZ with cLuaState::CheckParamXYZ --- src/Bindings/ManualBindings.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 451161d87..7255f73a4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -115,10 +115,10 @@ static int tolua_CompressStringZLIB(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !lua_isstring(tolua_S, 1) || + !S.CheckParamString(1) && ( - !lua_isnumber(tolua_S, 2) && - !lua_isnil(tolua_S, 2) + !S.CheckParamNumber(2) || + !S.CheckParamEnd(2) ) ) { @@ -146,8 +146,8 @@ static int tolua_UncompressStringZLIB(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !lua_isstring(tolua_S, 1) || - !lua_isnumber(tolua_S, 2) + !S.CheckParamString(1) && + !S.CheckParamNumber(2) ) { cLuaState::LogStackTrace(tolua_S); @@ -173,7 +173,10 @@ static int tolua_UncompressStringZLIB(lua_State * tolua_S) static int tolua_CompressStringGZIP(lua_State * tolua_S) { cLuaState S(tolua_S); - if (!lua_isstring(tolua_S, 1)) + if ( + !S.CheckParamString(1) && + !S.CheckParamEnd(2) + ) { cLuaState::LogStackTrace(tolua_S); return 0; @@ -198,15 +201,14 @@ static int tolua_UncompressStringGZIP(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !lua_isstring(tolua_S, 1) + !S.CheckParamString(1) && + !S.CheckParamEnd(2) ) { cLuaState::LogStackTrace(tolua_S); return 0; } - - // Get the params: AString ToUncompress; S.GetStackValues(1, ToUncompress); @@ -226,15 +228,14 @@ static int tolua_InflateString(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !lua_isstring(tolua_S, 1) + !S.CheckParamString(1) && + !S.CheckParamEnd(2) ) { cLuaState::LogStackTrace(tolua_S); return 0; } - - // Get the params: AString ToUncompress; S.GetStackValues(1, ToUncompress); -- cgit v1.2.3 From d39d2ca5e9592760246b11bdb0336e067ed8ee8a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 23 Feb 2015 15:40:31 +0100 Subject: Added forgotten indent --- src/Bindings/ManualBindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 7255f73a4..2e9d49ef0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -117,8 +117,8 @@ static int tolua_CompressStringZLIB(lua_State * tolua_S) if ( !S.CheckParamString(1) && ( - !S.CheckParamNumber(2) || - !S.CheckParamEnd(2) + !S.CheckParamNumber(2) || + !S.CheckParamEnd(2) ) ) { -- cgit v1.2.3 From 9e1db16ba497fd527b95fc00c69229de3957876d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 23 Feb 2015 16:09:35 +0100 Subject: Fixed operators --- src/Bindings/ManualBindings.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2e9d49ef0..a6ae4869b 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -115,9 +115,9 @@ static int tolua_CompressStringZLIB(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !S.CheckParamString(1) && + !S.CheckParamString(1) || ( - !S.CheckParamNumber(2) || + !S.CheckParamNumber(2) && !S.CheckParamEnd(2) ) ) @@ -146,7 +146,7 @@ static int tolua_UncompressStringZLIB(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !S.CheckParamString(1) && + !S.CheckParamString(1) || !S.CheckParamNumber(2) ) { @@ -174,7 +174,7 @@ static int tolua_CompressStringGZIP(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !S.CheckParamString(1) && + !S.CheckParamString(1) || !S.CheckParamEnd(2) ) { @@ -201,7 +201,7 @@ static int tolua_UncompressStringGZIP(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !S.CheckParamString(1) && + !S.CheckParamString(1) || !S.CheckParamEnd(2) ) { @@ -228,7 +228,7 @@ static int tolua_InflateString(lua_State * tolua_S) { cLuaState S(tolua_S); if ( - !S.CheckParamString(1) && + !S.CheckParamString(1) || !S.CheckParamEnd(2) ) { -- cgit v1.2.3 From d4b505db025b05379ac9a5df923a60f0d37eed9a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 3 Mar 2015 01:28:58 +0100 Subject: Lua API: Fixed md5 and sha1 hex formatting. std::setw() is only valid for one output operation and needs to be set again in each loop repetition. --- src/Bindings/ManualBindings.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index a6ae4869b..cac81f325 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2392,10 +2392,10 @@ static int tolua_md5HexString(lua_State * tolua_S) // Convert the md5 checksum to hex string: std::stringstream Output; - Output << std::hex << std::setw(2) << std::setfill('0'); + Output << std::hex << std::setfill('0'); for (size_t i = 0; i < ARRAYCOUNT(md5Output); i++) { - Output << static_cast(md5Output[i]); // Need to cast to a number, otherwise a char is output + Output << std::setw(2) << static_cast(md5Output[i]); // Need to cast to a number, otherwise a char is output } lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size()); return 1; @@ -2438,10 +2438,10 @@ static int tolua_sha1HexString(lua_State * tolua_S) // Convert the sha1 checksum to hex string: std::stringstream Output; - Output << std::hex << std::setw(2) << std::setfill('0'); + Output << std::hex << std::setfill('0'); for (size_t i = 0; i < ARRAYCOUNT(sha1Output); i++) { - Output << static_cast(sha1Output[i]); // Need to cast to a number, otherwise a char is output + Output << std::setw(2) << static_cast(sha1Output[i]); // Need to cast to a number, otherwise a char is output } lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size()); return 1; -- cgit v1.2.3