summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2015-02-23 12:53:02 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2015-02-23 12:53:02 +0100
commit54410bfe4dac8793d6b46df725c400f7ce8d365e (patch)
tree6124eb0d20c4dd552f4e3f9825c0b24ae5b314b3 /src/Bindings
parentDocumented CompressString and UncompressString (diff)
downloadcuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar.gz
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar.bz2
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar.lz
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar.xz
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.tar.zst
cuberite-54410bfe4dac8793d6b46df725c400f7ce8d365e.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/ManualBindings.cpp145
1 files changed, 129 insertions, 16 deletions
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);