Expose love.markDeprecated.

Arguments are (level, name, apitype, deprecationtype [, replacementname]). Call it inside a function.
This commit is contained in:
Alex Szpakowski
2021-06-06 18:16:56 -03:00
parent 199632e791
commit 5ef1709c02
7 changed files with 66 additions and 13 deletions
+20
View File
@@ -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
+7
View File
@@ -21,6 +21,7 @@
#pragma once
#include "int.h"
#include "StringMap.h"
#include <string>
#include <vector>
@@ -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
+4 -4
View File
@@ -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;
+2 -2
View File
@@ -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);