From cbf7e5680acd58ffe67910adc407a06e8617596e Mon Sep 17 00:00:00 2001 From: EngineerSmith <56016593+EngineerSmith@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:01:18 +0000 Subject: [PATCH] Added old functionality back, and marked it as deprecated --- src/modules/data/wrap_DataModule.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/data/wrap_DataModule.cpp b/src/modules/data/wrap_DataModule.cpp index eafd37931..d77186563 100644 --- a/src/modules/data/wrap_DataModule.cpp +++ b/src/modules/data/wrap_DataModule.cpp @@ -302,22 +302,37 @@ int w_decode(lua_State *L) int w_hash(lua_State *L) { - ContainerType ctype = luax_checkcontainertype(L, 1); - const char *fstr = luaL_checkstring(L, 2); + int narg = 0; // used to change the arg position when using the deprecated function variant + + ContainerType ctype = CONTAINER_STRING; HashFunction::Function function; + + const char *str = luaL_checkstring(L, 1); + if (!getConstant(str, ctype)) + { + if (HashFunction::getConstant(str, function)) + { // check if the argument at 1 is a hash function; deprecated function variant + luax_markdeprecated(L, 1, "love.data.hash", API_FUNCTION_VARIANT, DEPRECATED_REPLACED, "variant with container return type parameter"); + narg = -1; + } + else + luax_enumerror(L, "container type", getConstants(ctype), str); + } + + const char *fstr = luaL_checkstring(L, 2 + narg); if (!HashFunction::getConstant(fstr, function)) return luax_enumerror(L, "hash function", HashFunction::getConstants(function), fstr); HashFunction::Value hashvalue; - if (lua_isstring(L, 3)) + if (lua_isstring(L, 3 + narg)) { size_t rawsize = 0; - const char *rawbytes = luaL_checklstring(L, 3, &rawsize); + const char *rawbytes = luaL_checklstring(L, 3 + narg, &rawsize); luax_catchexcept(L, [&](){ love::data::hash(function, rawbytes, rawsize, hashvalue); }); } else { - Data *rawdata = luax_checktype(L, 3); + Data *rawdata = luax_checktype(L, 3 + narg); luax_catchexcept(L, [&](){ love::data::hash(function, rawdata, hashvalue); }); }