mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
Expose love.markDeprecated.
Arguments are (level, name, apitype, deprecationtype [, replacementname]). Call it inside a function.
This commit is contained in:
@@ -108,6 +108,8 @@ std::string getDeprecationNotice(const DeprecationInfo &info, bool usewhere)
|
|||||||
notice += "function ";
|
notice += "function ";
|
||||||
else if (info.apiType == API_METHOD)
|
else if (info.apiType == API_METHOD)
|
||||||
notice += "method ";
|
notice += "method ";
|
||||||
|
else if (info.apiType == API_CALLBACK)
|
||||||
|
notice += "callback ";
|
||||||
else if (info.apiType == API_FIELD)
|
else if (info.apiType == API_FIELD)
|
||||||
notice += "field ";
|
notice += "field ";
|
||||||
else if (info.apiType == API_CONSTANT)
|
else if (info.apiType == API_CONSTANT)
|
||||||
@@ -184,4 +186,22 @@ MarkDeprecated::~MarkDeprecated()
|
|||||||
mutex->unlock();
|
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
|
} // love
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "int.h"
|
#include "int.h"
|
||||||
|
#include "StringMap.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -32,8 +33,10 @@ enum APIType
|
|||||||
{
|
{
|
||||||
API_FUNCTION,
|
API_FUNCTION,
|
||||||
API_METHOD,
|
API_METHOD,
|
||||||
|
API_CALLBACK,
|
||||||
API_FIELD,
|
API_FIELD,
|
||||||
API_CONSTANT,
|
API_CONSTANT,
|
||||||
|
API_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DeprecationType
|
enum DeprecationType
|
||||||
@@ -41,6 +44,7 @@ enum DeprecationType
|
|||||||
DEPRECATED_NO_REPLACEMENT,
|
DEPRECATED_NO_REPLACEMENT,
|
||||||
DEPRECATED_REPLACED,
|
DEPRECATED_REPLACED,
|
||||||
DEPRECATED_RENAMED,
|
DEPRECATED_RENAMED,
|
||||||
|
DEPRECATED_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeprecationInfo
|
struct DeprecationInfo
|
||||||
@@ -78,4 +82,7 @@ struct MarkDeprecated
|
|||||||
DeprecationInfo *info;
|
DeprecationInfo *info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
STRINGMAP_DECLARE(APIType);
|
||||||
|
STRINGMAP_DECLARE(DeprecationType);
|
||||||
|
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -1061,18 +1061,18 @@ lua_State *luax_getpinnedthread(lua_State *L)
|
|||||||
return thread;
|
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);
|
MarkDeprecated deprecated(name, api, type, replacement);
|
||||||
|
|
||||||
if (deprecated.info != nullptr && deprecated.info->uses == 1)
|
if (deprecated.info != nullptr && deprecated.info->uses == 1)
|
||||||
{
|
{
|
||||||
luaL_where(L, 1);
|
luaL_where(L, level);
|
||||||
const char *where = lua_tostring(L, -1);
|
const char *where = lua_tostring(L, -1);
|
||||||
if (where != nullptr)
|
if (where != nullptr)
|
||||||
deprecated.info->where = where;
|
deprecated.info->where = where;
|
||||||
|
|||||||
@@ -482,8 +482,8 @@ lua_State *luax_getpinnedthread(lua_State *L);
|
|||||||
* Mark a function as deprecated. Should only be called inside wrapper function
|
* Mark a function as deprecated. Should only be called inside wrapper function
|
||||||
* code.
|
* code.
|
||||||
**/
|
**/
|
||||||
void luax_markdeprecated(lua_State *L, const char *name, APIType api);
|
void luax_markdeprecated(lua_State *L, int level, 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, DeprecationType type, const char *replacement);
|
||||||
|
|
||||||
extern "C" { // Also called from luasocket
|
extern "C" { // Also called from luasocket
|
||||||
int luax_typerror(lua_State *L, int narg, const char *tname);
|
int luax_typerror(lua_State *L, int narg, const char *tname);
|
||||||
|
|||||||
@@ -1195,25 +1195,25 @@ int w_newVolumeTexture(lua_State *L)
|
|||||||
|
|
||||||
int w_newImage(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);
|
return w_newTexture(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_newCubeImage(lua_State *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);
|
return w_newCubeTexture(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_newArrayImage(lua_State *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);
|
return w_newArrayTexture(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_newVolumeImage(lua_State *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);
|
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)
|
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);
|
bool (*supported)(PixelFormat);
|
||||||
|
|
||||||
@@ -2681,7 +2681,7 @@ int w_getCanvasFormats(lua_State *L)
|
|||||||
|
|
||||||
int w_getImageFormats(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
|
const auto supported = [](PixelFormat format) -> bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -352,6 +352,29 @@ static int w__requestRecordingPermission(lua_State *L)
|
|||||||
return 0;
|
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)
|
static int w_love_setDeprecationOutput(lua_State *L)
|
||||||
{
|
{
|
||||||
bool enable = love::luax_checkboolean(L, 1);
|
bool enable = love::luax_checkboolean(L, 1);
|
||||||
@@ -482,6 +505,9 @@ int luaopen_love(lua_State *L)
|
|||||||
|
|
||||||
lua_setfield(L, -2, "_deprecation");
|
lua_setfield(L, -2, "_deprecation");
|
||||||
|
|
||||||
|
lua_pushcfunction(L, w_love_markDeprecated);
|
||||||
|
lua_setfield(L, -2, "markDeprecated");
|
||||||
|
|
||||||
lua_pushcfunction(L, w_love_setDeprecationOutput);
|
lua_pushcfunction(L, w_love_setDeprecationOutput);
|
||||||
lua_setfield(L, -2, "setDeprecationOutput");
|
lua_setfield(L, -2, "setDeprecationOutput");
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings)
|
|||||||
lua_getfield(L, idx, settingName(Window::SETTING_HIGHDPI));
|
lua_getfield(L, idx, settingName(Window::SETTING_HIGHDPI));
|
||||||
if (!lua_isnoneornil(L, -1))
|
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);
|
bool highdpi = luax_checkboolean(L, -1);
|
||||||
if (!instance()->isOpen())
|
if (!instance()->isOpen())
|
||||||
setHighDPIAllowed(highdpi);
|
setHighDPIAllowed(highdpi);
|
||||||
|
|||||||
Reference in New Issue
Block a user