Skip to content

Commit

Permalink
Added old functionality back, and marked it as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
EngineerSmith committed Feb 13, 2024
1 parent f00a86d commit cbf7e56
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/modules/data/wrap_DataModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data>(L, 3);
Data *rawdata = luax_checktype<Data>(L, 3 + narg);
luax_catchexcept(L, [&](){ love::data::hash(function, rawdata, hashvalue); });
}

Expand Down

0 comments on commit cbf7e56

Please sign in to comment.