diff --git a/src/common/deprecation.cpp b/src/common/deprecation.cpp index 84e82d78b..5c7fa28c1 100644 --- a/src/common/deprecation.cpp +++ b/src/common/deprecation.cpp @@ -108,6 +108,8 @@ std::string getDeprecationNotice(const DeprecationInfo &info, bool usewhere) notice += "function "; else if (info.apiType == API_METHOD) notice += "method "; + else if (info.apiType == API_CALLBACK) + notice += "callback "; else if (info.apiType == API_FIELD) notice += "field "; else if (info.apiType == API_CONSTANT) @@ -184,4 +186,22 @@ MarkDeprecated::~MarkDeprecated() mutex->unlock(); } +STRINGMAP_BEGIN(APIType, API_MAX_ENUM, apiType) +{ + { "function", API_FUNCTION }, + { "method", API_METHOD }, + { "callback", API_CALLBACK }, + { "field", API_FIELD }, + { "constant", API_CONSTANT }, +} +STRINGMAP_END(APIType, API_MAX_ENUM, apiType) + +STRINGMAP_BEGIN(DeprecationType, DEPRECATED_MAX_ENUM, deprecationType) +{ + { "noreplacement", DEPRECATED_NO_REPLACEMENT }, + { "replaced", DEPRECATED_REPLACED }, + { "renamed", DEPRECATED_RENAMED }, +} +STRINGMAP_END(DeprecationType, DEPRECATED_MAX_ENUM, deprecationType) + } // love diff --git a/src/common/deprecation.h b/src/common/deprecation.h index 5eea087e9..33c2eac11 100644 --- a/src/common/deprecation.h +++ b/src/common/deprecation.h @@ -21,6 +21,7 @@ #pragma once #include "int.h" +#include "StringMap.h" #include #include @@ -32,8 +33,10 @@ enum APIType { API_FUNCTION, API_METHOD, + API_CALLBACK, API_FIELD, API_CONSTANT, + API_MAX_ENUM }; enum DeprecationType @@ -41,6 +44,7 @@ enum DeprecationType DEPRECATED_NO_REPLACEMENT, DEPRECATED_REPLACED, DEPRECATED_RENAMED, + DEPRECATED_MAX_ENUM }; struct DeprecationInfo @@ -78,4 +82,7 @@ struct MarkDeprecated DeprecationInfo *info; }; +STRINGMAP_DECLARE(APIType); +STRINGMAP_DECLARE(DeprecationType); + } // love diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 3116d5dde..2eb972fad 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -1061,18 +1061,18 @@ lua_State *luax_getpinnedthread(lua_State *L) return thread; } -void luax_markdeprecated(lua_State *L, const char *name, APIType api) +void luax_markdeprecated(lua_State *L, int level, const char *name, APIType api) { - luax_markdeprecated(L, name, api, DEPRECATED_NO_REPLACEMENT, nullptr); + luax_markdeprecated(L, level, name, api, DEPRECATED_NO_REPLACEMENT, nullptr); } -void luax_markdeprecated(lua_State *L, const char *name, APIType api, DeprecationType type, const char *replacement) +void luax_markdeprecated(lua_State *L, int level, const char *name, APIType api, DeprecationType type, const char *replacement) { MarkDeprecated deprecated(name, api, type, replacement); if (deprecated.info != nullptr && deprecated.info->uses == 1) { - luaL_where(L, 1); + luaL_where(L, level); const char *where = lua_tostring(L, -1); if (where != nullptr) deprecated.info->where = where; diff --git a/src/common/runtime.h b/src/common/runtime.h index f0f343bd1..06e46f8c1 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -482,8 +482,8 @@ lua_State *luax_getpinnedthread(lua_State *L); * Mark a function as deprecated. Should only be called inside wrapper function * code. **/ -void luax_markdeprecated(lua_State *L, const char *name, APIType api); -void luax_markdeprecated(lua_State *L, const char *name, APIType api, DeprecationType type, const char *replacement); +void luax_markdeprecated(lua_State *L, int level, const char *name, APIType api); +void luax_markdeprecated(lua_State *L, int level, const char *name, APIType api, DeprecationType type, const char *replacement); extern "C" { // Also called from luasocket int luax_typerror(lua_State *L, int narg, const char *tname); diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 169b7852c..654d2668a 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -1195,25 +1195,25 @@ int w_newVolumeTexture(lua_State *L) int w_newImage(lua_State *L) { - //luax_markdeprecated(L, "love.graphics.newImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newTexture"); + //luax_markdeprecated(L, 1, "love.graphics.newImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newTexture"); return w_newTexture(L); } int w_newCubeImage(lua_State *L) { - //luax_markdeprecated(L, "love.graphics.newCubeImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newCubeTexture"); + //luax_markdeprecated(L, 1, "love.graphics.newCubeImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newCubeTexture"); return w_newCubeTexture(L); } int w_newArrayImage(lua_State *L) { - //luax_markdeprecated(L, "love.graphics.newArrayImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newArrayTexture"); + //luax_markdeprecated(L, 1, "love.graphics.newArrayImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newArrayTexture"); return w_newArrayTexture(L); } int w_newVolumeImage(lua_State *L) { - //luax_markdeprecated(L, "love.graphics.newVolumeImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newVolumeTexture"); + //luax_markdeprecated(L, 1, "love.graphics.newVolumeImage", API_FUNCTION, DEPRECATED_RENAMED, "love.graphics.newVolumeTexture"); return w_newVolumeTexture(L); } @@ -2644,7 +2644,7 @@ static int w__getFormats(lua_State *L, int idx, bool (*isFormatSupported)(PixelF int w_getCanvasFormats(lua_State *L) { - luax_markdeprecated(L, "love.graphics.getCanvasFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats"); + luax_markdeprecated(L, 1, "love.graphics.getCanvasFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats"); bool (*supported)(PixelFormat); @@ -2681,7 +2681,7 @@ int w_getCanvasFormats(lua_State *L) int w_getImageFormats(lua_State *L) { - luax_markdeprecated(L, "love.graphics.getImageFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats"); + luax_markdeprecated(L, 1, "love.graphics.getImageFormats", API_FUNCTION, DEPRECATED_REPLACED, "love.graphics.getTextureFormats"); const auto supported = [](PixelFormat format) -> bool { diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 50eaa633d..9ae8f5c2e 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -352,6 +352,29 @@ static int w__requestRecordingPermission(lua_State *L) return 0; } +static int w_love_markDeprecated(lua_State *L) +{ + int level = (int)luaL_checkinteger(L, 1); + const char *name = luaL_checkstring(L, 2); + const char *apiname = luaL_checkstring(L, 3); + const char *deprecationtname = luaL_checkstring(L, 4); + + love::APIType api; + if (!love::getConstant(apiname, api)) + return love::luax_enumerror(L, "API type", love::getConstants(api), apiname); + + love::DeprecationType dtype; + if (!love::getConstant(deprecationtname, dtype)) + return love::luax_enumerror(L, "deprecation type", love::getConstants(dtype), deprecationtname); + + const char *replacement = nullptr; + if (dtype != love::DEPRECATED_NO_REPLACEMENT) + replacement = luaL_checkstring(L, 5); + + love::luax_markdeprecated(L, level, name, api, dtype, replacement); + return 0; +} + static int w_love_setDeprecationOutput(lua_State *L) { bool enable = love::luax_checkboolean(L, 1); @@ -482,6 +505,9 @@ int luaopen_love(lua_State *L) lua_setfield(L, -2, "_deprecation"); + lua_pushcfunction(L, w_love_markDeprecated); + lua_setfield(L, -2, "markDeprecated"); + lua_pushcfunction(L, w_love_setDeprecationOutput); lua_setfield(L, -2, "setDeprecationOutput"); diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index 28f0567d3..c8a093dcd 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -80,7 +80,7 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings) lua_getfield(L, idx, settingName(Window::SETTING_HIGHDPI)); if (!lua_isnoneornil(L, -1)) { - luax_markdeprecated(L, "window.highdpi", API_FIELD, DEPRECATED_REPLACED, "t.highdpi in love.conf"); + luax_markdeprecated(L, 1, "window.highdpi", API_FIELD, DEPRECATED_REPLACED, "t.highdpi in love.conf"); bool highdpi = luax_checkboolean(L, -1); if (!instance()->isOpen()) setHighDPIAllowed(highdpi);