diff --git a/src/logic/scripting/lua/libs/libbase64.cpp b/src/logic/scripting/lua/libs/libbase64.cpp index 5d50f1e8..faf718de 100644 --- a/src/logic/scripting/lua/libs/libbase64.cpp +++ b/src/logic/scripting/lua/libs/libbase64.cpp @@ -2,6 +2,7 @@ #include "util/stringutil.hpp" +template static int l_encode(lua::State* L) { if (lua::istable(L, 1)) { lua::pushvalue(L, 1); @@ -13,12 +14,12 @@ static int l_encode(lua::State* L) { lua::pop(L); } lua::pop(L); - return lua::pushstring(L, util::base64_encode( + return lua::pushstring(L, encode_func( reinterpret_cast(buffer.data()), buffer.size() )); } else { auto string = lua::bytearray_as_string(L, 1); - auto out = util::base64_encode( + auto out = encode_func( reinterpret_cast(string.data()), string.size() ); @@ -28,8 +29,9 @@ static int l_encode(lua::State* L) { throw std::runtime_error("array or ByteArray expected"); } +template(*decode_func)(std::string_view)> static int l_decode(lua::State* L) { - auto buffer = util::base64_decode(lua::require_lstring(L, 1)); + auto buffer = decode_func(lua::require_lstring(L, 1)); if (lua::toboolean(L, 2)) { lua::createtable(L, buffer.size(), 0); for (size_t i = 0; i < buffer.size(); i++) { @@ -43,7 +45,9 @@ static int l_decode(lua::State* L) { } const luaL_Reg base64lib[] = { - {"encode", lua::wrap}, - {"decode", lua::wrap}, + {"encode", lua::wrap>}, + {"decode", lua::wrap>}, + {"encode_urlsafe", lua::wrap>}, + {"decode_urlsafe", lua::wrap>}, {NULL, NULL} };