Merge pull request #1762 from mc-server/LuaStringCompress
Lua string compress
This commit is contained in:
commit
81c49a0246
@ -2254,6 +2254,27 @@ end
|
||||
ShouldAuthenticate = { Params = "", Return = "bool", Notes = "Returns true iff the server is set to authenticate players (\"online mode\")." },
|
||||
},
|
||||
}, -- cServer
|
||||
|
||||
cStringCompression =
|
||||
{
|
||||
Desc = [[
|
||||
Provides functions to compress or decompress string
|
||||
<p>
|
||||
All functions in this class are static, so they should be called in the dot convention:
|
||||
<pre class="prettyprint lang-lua">
|
||||
local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress")
|
||||
</pre>
|
||||
]],
|
||||
|
||||
Functions =
|
||||
{
|
||||
CompressStringGZIP = {Params = "string", Return = "string", Notes = "Compress a string using GZIP"},
|
||||
CompressStringZLIB = {Params = "string, factor", Return = "string", Notes = "Compresses a string using ZLIB. Factor 0 is no compression and factor 9 is maximum compression"},
|
||||
InflateString = {Params = "string", Return = "string", Notes = "Uncompresses a string using Inflate"},
|
||||
UncompressStringGZIP = {Params = "string", Return = "string", Notes = "Uncompress a string using GZIP"},
|
||||
UncompressStringZLIB = {Params = "string, uncompressed length", Return = "string", Notes = "Uncompresses a string using ZLIB"},
|
||||
},
|
||||
},
|
||||
|
||||
cTeam =
|
||||
{
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "../LineBlockTracer.h"
|
||||
#include "../WorldStorage/SchematicFileSerializer.h"
|
||||
#include "../CompositeChat.h"
|
||||
#include "../StringCompression.h"
|
||||
|
||||
|
||||
|
||||
@ -110,6 +111,146 @@ static int tolua_Clamp(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_CompressStringZLIB(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState S(tolua_S);
|
||||
if (
|
||||
!S.CheckParamString(1) ||
|
||||
(
|
||||
!S.CheckParamNumber(2) &&
|
||||
!S.CheckParamEnd(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_UncompressStringZLIB(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState S(tolua_S);
|
||||
if (
|
||||
!S.CheckParamString(1) ||
|
||||
!S.CheckParamNumber(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_CompressStringGZIP(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState S(tolua_S);
|
||||
if (
|
||||
!S.CheckParamString(1) ||
|
||||
!S.CheckParamEnd(2)
|
||||
)
|
||||
{
|
||||
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 (
|
||||
!S.CheckParamString(1) ||
|
||||
!S.CheckParamEnd(2)
|
||||
)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_InflateString(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState S(tolua_S);
|
||||
if (
|
||||
!S.CheckParamString(1) ||
|
||||
!S.CheckParamEnd(2)
|
||||
)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_StringSplit(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState LuaState(tolua_S);
|
||||
@ -3516,6 +3657,8 @@ 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);
|
||||
@ -3692,6 +3835,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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user