Updates Angelscript addons, adds angelscript dictionary addon.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-03-27 22:39:25 +01:00
parent e5b2ff5c59
commit e748f6e96f
10 changed files with 1921 additions and 376 deletions

View File

@@ -28,25 +28,26 @@ typedef map<string, int> map_t;
END_AS_NAMESPACE
#endif
BEGIN_AS_NAMESPACE
class CStdStringFactory : public asIStringFactory
{
public:
CStdStringFactory() = default;
~CStdStringFactory() override
CStdStringFactory() {}
~CStdStringFactory()
{
// The script engine must release each string
// constant that it has requested
assert(stringCache.empty());
assert(stringCache.size() == 0);
}
const void *GetStringConstant(const char *data, asUINT length) override
const void *GetStringConstant(const char *data, asUINT length)
{
// The string factory might be modified from multiple
// threads, so it is necessary to use a mutex.
asAcquireExclusiveLock();
string str(data, length);
auto it = stringCache.find(str);
map_t::iterator it = stringCache.find(str);
if (it != stringCache.end())
it->second++;
else
@@ -57,9 +58,9 @@ public:
return reinterpret_cast<const void*>(&it->first);
}
int ReleaseStringConstant(const void *str) override
int ReleaseStringConstant(const void *str)
{
if (str == nullptr)
if (str == 0)
return asERROR;
int ret = asSUCCESS;
@@ -68,7 +69,7 @@ public:
// threads, so it is necessary to use a mutex.
asAcquireExclusiveLock();
auto it = stringCache.find(*reinterpret_cast<const string*>(str));
map_t::iterator it = stringCache.find(*reinterpret_cast<const string*>(str));
if (it == stringCache.end())
ret = asERROR;
else
@@ -83,9 +84,9 @@ public:
return ret;
}
int GetRawStringData(const void *str, char *data, asUINT *length) const override
int GetRawStringData(const void *str, char *data, asUINT *length) const
{
if (str == nullptr)
if (str == 0)
return asERROR;
if (length)
@@ -98,17 +99,17 @@ public:
}
// THe access to the string cache is protected with the common mutex provided by AngelScript
map_t stringCache = {};
map_t stringCache;
};
static CStdStringFactory *stringFactory = nullptr;
static CStdStringFactory *stringFactory = 0;
// TODO: Make this public so the application can also use the string
// factory and share the string constants if so desired, or to
// monitor the size of the string factory cache.
CStdStringFactory *GetStdStringFactorySingleton()
{
if( stringFactory == nullptr )
if( stringFactory == 0 )
{
// The following instance will be destroyed by the global
// CStdStringFactoryCleaner instance upon application shutdown
@@ -122,7 +123,7 @@ class CStdStringFactoryCleaner
public:
~CStdStringFactoryCleaner()
{
if (stringFactory != nullptr)
if (stringFactory)
{
// Only delete the string factory if the stringCache is empty
// If it is not empty, it means that someone might still attempt
@@ -133,13 +134,13 @@ public:
if (stringFactory->stringCache.empty())
{
delete stringFactory;
stringFactory = nullptr;
stringFactory = 0;
}
}
}
};
static CStdStringFactoryCleaner cleaner = {};
static CStdStringFactoryCleaner cleaner;
static void ConstructString(string *thisPointer)
@@ -461,12 +462,12 @@ static void StringResize(asUINT l, string &str)
// string formatInt(int64 val, const string &in options, uint width)
static string formatInt(asINT64 value, const string &options, asUINT width)
{
bool leftJustify = options.find('l') != string::npos;
bool padWithZero = options.find('0') != string::npos;
bool alwaysSign = options.find('+') != string::npos;
bool spaceOnSign = options.find(' ') != string::npos;
bool hexSmall = options.find('h') != string::npos;
bool hexLarge = options.find('H') != string::npos;
bool leftJustify = options.find("l") != string::npos;
bool padWithZero = options.find("0") != string::npos;
bool alwaysSign = options.find("+") != string::npos;
bool spaceOnSign = options.find(" ") != string::npos;
bool hexSmall = options.find("h") != string::npos;
bool hexLarge = options.find("H") != string::npos;
string fmt = "%";
if( leftJustify ) fmt += "-";
@@ -505,12 +506,12 @@ static string formatInt(asINT64 value, const string &options, asUINT width)
// string formatUInt(uint64 val, const string &in options, uint width)
static string formatUInt(asQWORD value, const string &options, asUINT width)
{
bool leftJustify = options.find('l') != string::npos;
bool padWithZero = options.find('0') != string::npos;
bool alwaysSign = options.find('+') != string::npos;
bool spaceOnSign = options.find(' ') != string::npos;
bool hexSmall = options.find('h') != string::npos;
bool hexLarge = options.find('H') != string::npos;
bool leftJustify = options.find("l") != string::npos;
bool padWithZero = options.find("0") != string::npos;
bool alwaysSign = options.find("+") != string::npos;
bool spaceOnSign = options.find(" ") != string::npos;
bool hexSmall = options.find("h") != string::npos;
bool hexLarge = options.find("H") != string::npos;
string fmt = "%";
if( leftJustify ) fmt += "-";
@@ -549,12 +550,12 @@ static string formatUInt(asQWORD value, const string &options, asUINT width)
// string formatFloat(double val, const string &in options, uint width, uint precision)
static string formatFloat(double value, const string &options, asUINT width, asUINT precision)
{
bool leftJustify = options.find('l') != string::npos;
bool padWithZero = options.find('0') != string::npos;
bool alwaysSign = options.find('+') != string::npos;
bool spaceOnSign = options.find(' ') != string::npos;
bool expSmall = options.find('e') != string::npos;
bool expLarge = options.find('E') != string::npos;
bool leftJustify = options.find("l") != string::npos;
bool padWithZero = options.find("0") != string::npos;
bool alwaysSign = options.find("+") != string::npos;
bool spaceOnSign = options.find(" ") != string::npos;
bool expSmall = options.find("e") != string::npos;
bool expLarge = options.find("E") != string::npos;
string fmt = "%";
if( leftJustify ) fmt += "-";
@@ -734,7 +735,7 @@ static string StringSubString(asUINT start, int count, const string &str)
// makro, so this wrapper was introduced as work around.
static bool StringEquals(const std::string& lhs, const std::string& rhs)
{
return lhs == rhs;
return lhs == rhs;
}
void RegisterStdString_Native(asIScriptEngine *engine)

View File

@@ -112,8 +112,7 @@ static void StringJoin_Generic(asIScriptGeneric *gen)
// The string type must have been registered first.
void RegisterStdStringUtils(asIScriptEngine *engine)
{
[[maybe_unused]]
int r;
int r;
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
{