Update to Angelscript 2.35.1
This commit is contained in:
@@ -551,12 +551,9 @@ struct Id {
|
||||
template <typename T>
|
||||
Id<T> id(T /*fn_ptr*/) { return Id<T>(); }
|
||||
|
||||
// On some versions of GNUC it is necessary to use the template keyword as disambiguator,
|
||||
// on others the template keyword gives an error, hence the need for the following define.
|
||||
// MSVC on the other hand seems to accept both with or without the template keyword.
|
||||
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
|
||||
// GNUC 4.4.3 doesn't need the template keyword, and
|
||||
// hopefully upcoming versions won't need it either
|
||||
// On GNUC it is necessary to use the template keyword as disambiguator.
|
||||
// MSVC seems to accept both with or without the template keyword.
|
||||
#if defined(__GNUC__)
|
||||
#define TMPL template
|
||||
#else
|
||||
#define TMPL
|
||||
@@ -568,7 +565,7 @@ Id<T> id(T /*fn_ptr*/) { return Id<T>(); }
|
||||
#define WRAP_OBJ_LAST(name) (::gw::id(name).TMPL ol< name >())
|
||||
|
||||
#define WRAP_FN_PR(name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (*)Parameters>::TMPL f< name >))
|
||||
#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (ClassType::*)Parameters>::TMPL f< &ClassType::name >))
|
||||
#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (ClassType::*)Parameters>::TMPL f< AS_METHOD_AMBIGUITY_CAST(ReturnType (ClassType::*)Parameters)(&ClassType::name) >))
|
||||
#define WRAP_OBJ_FIRST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjFirst<ReturnType (*)Parameters>::TMPL f< name >))
|
||||
#define WRAP_OBJ_LAST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjLast<ReturnType (*)Parameters>::TMPL f< name >))
|
||||
|
||||
|
||||
@@ -113,12 +113,9 @@ int main()
|
||||
"template <typename T>\n"
|
||||
"Id<T> id(T fn_ptr) { return Id<T>(); }\n"
|
||||
"\n"
|
||||
"// On some versions of GNUC it is necessary to use the template keyword as disambiguator,\n"
|
||||
"// on others the template keyword gives an error, hence the need for the following define.\n"
|
||||
"// MSVC on the other hand seems to accept both with or without the template keyword.\n"
|
||||
"#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))\n"
|
||||
" // GNUC 4.4.3 doesn't need the template keyword, and\n"
|
||||
" // hopefully upcoming versions won't need it either\n"
|
||||
"// On GNUC it is necessary to use the template keyword as disambiguator.\n"
|
||||
"// MSVC seems to accept both with or without the template keyword.\n"
|
||||
"#if defined(__GNUC__)\n"
|
||||
" #define TMPL template\n"
|
||||
"#else\n"
|
||||
" #define TMPL\n"
|
||||
@@ -130,7 +127,7 @@ int main()
|
||||
"#define WRAP_OBJ_LAST(name) (::gw::id(name).TMPL ol< name >())\n"
|
||||
"\n"
|
||||
"#define WRAP_FN_PR(name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (*)Parameters>::TMPL f< name >))\n"
|
||||
"#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (ClassType::*)Parameters>::TMPL f< &ClassType::name >))\n"
|
||||
"#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper<ReturnType (ClassType::*)Parameters>::TMPL f< AS_METHOD_AMBIGUITY_CAST(ReturnType (ClassType::*)Parameters)(&ClassType::name) >))\n"
|
||||
"#define WRAP_OBJ_FIRST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjFirst<ReturnType (*)Parameters>::TMPL f< name >))\n"
|
||||
"#define WRAP_OBJ_LAST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjLast<ReturnType (*)Parameters>::TMPL f< name >))\n"
|
||||
"\n"
|
||||
|
||||
@@ -20,6 +20,7 @@ static tm time_point_to_tm(const std::chrono::time_point<std::chrono::system_clo
|
||||
#ifdef _MSC_VER
|
||||
gmtime_s(&local, &t);
|
||||
#else
|
||||
// TODO: gmtime is not threadsafe
|
||||
local = *gmtime(&t);
|
||||
#endif
|
||||
return local;
|
||||
@@ -33,23 +34,15 @@ static bool tm_to_time_point(const tm &_tm, std::chrono::time_point<std::chrono:
|
||||
// Do not rely on timezone, as it is not portable
|
||||
// ref: https://stackoverflow.com/questions/38298261/why-there-is-no-inverse-function-for-gmtime-in-libc
|
||||
// ref: https://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
|
||||
localTm.tm_isdst = -1; // Always use current settings, so mktime doesn't modify the time for daylight savings
|
||||
// TODO: mktime is not threadsafe
|
||||
time_t t = mktime(&localTm);
|
||||
if (t == -1)
|
||||
return false;
|
||||
|
||||
// Adjust the time_t since epoch with the difference of the local timezone to the universal timezone
|
||||
// TODO: localtime, gmtime, and mktime are not threadsafe
|
||||
t += (mktime(localtime(&t)) - mktime(gmtime(&t)));
|
||||
|
||||
// Verify if the members were modified, indicating an out-of-range value in input
|
||||
if (localTm.tm_year != _tm.tm_year ||
|
||||
localTm.tm_mon != _tm.tm_mon ||
|
||||
localTm.tm_mday != _tm.tm_mday ||
|
||||
localTm.tm_hour != _tm.tm_hour ||
|
||||
localTm.tm_min != _tm.tm_min ||
|
||||
localTm.tm_sec != _tm.tm_sec)
|
||||
return false;
|
||||
|
||||
tp = system_clock::from_time_t(t);
|
||||
return true;
|
||||
}
|
||||
@@ -111,7 +104,20 @@ bool CDateTime::setDate(asUINT year, asUINT month, asUINT day)
|
||||
local.tm_mon = month - 1;
|
||||
local.tm_mday = day;
|
||||
|
||||
return tm_to_time_point(local, tp);
|
||||
std::chrono::time_point<std::chrono::system_clock> newTp;
|
||||
if (!tm_to_time_point(local, newTp))
|
||||
return false;
|
||||
|
||||
// Check if the date was actually valid
|
||||
tm local2 = time_point_to_tm(newTp);
|
||||
|
||||
if (local.tm_year != local2.tm_year ||
|
||||
local.tm_mon != local2.tm_mon ||
|
||||
local.tm_mday != local2.tm_mday)
|
||||
return false;
|
||||
|
||||
tp = newTp;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDateTime::setTime(asUINT hour, asUINT minute, asUINT second)
|
||||
@@ -121,7 +127,20 @@ bool CDateTime::setTime(asUINT hour, asUINT minute, asUINT second)
|
||||
local.tm_min = minute;
|
||||
local.tm_sec = second;
|
||||
|
||||
return tm_to_time_point(local, tp);
|
||||
std::chrono::time_point<std::chrono::system_clock> newTp;
|
||||
if (!tm_to_time_point(local, newTp))
|
||||
return false;
|
||||
|
||||
// Check if the time was actually valid
|
||||
tm local2 = time_point_to_tm(newTp);
|
||||
|
||||
if (local.tm_hour != local2.tm_hour ||
|
||||
local.tm_min != local2.tm_min ||
|
||||
local.tm_sec != local2.tm_sec)
|
||||
return false;
|
||||
|
||||
tp = newTp;
|
||||
return true;
|
||||
}
|
||||
|
||||
CDateTime::CDateTime(asUINT year, asUINT month, asUINT day, asUINT hour, asUINT minute, asUINT second)
|
||||
|
||||
@@ -1331,6 +1331,19 @@ void CScriptArray::Copy(void *dst, void *src)
|
||||
}
|
||||
|
||||
|
||||
// internal
|
||||
// Swap two elements
|
||||
// Even in arrays of objects the objects are allocated on
|
||||
// the heap and the array stores the pointers to the objects.
|
||||
void CScriptArray::Swap(void* a, void* b)
|
||||
{
|
||||
asBYTE tmp[16];
|
||||
Copy(tmp, a);
|
||||
Copy(a, b);
|
||||
Copy(b, tmp);
|
||||
}
|
||||
|
||||
|
||||
// internal
|
||||
// Return pointer to array item (object handle or primitive value)
|
||||
void *CScriptArray::GetArrayItemPointer(int index)
|
||||
@@ -1574,32 +1587,31 @@ void CScriptArray::Sort(asIScriptFunction *func, asUINT startAt, asUINT count)
|
||||
if (cmpContext == 0)
|
||||
cmpContext = objType->GetEngine()->RequestContext();
|
||||
|
||||
// Insertion sort
|
||||
asBYTE tmp[16];
|
||||
for (asUINT i = start + 1; i < end; i++)
|
||||
// TODO: Security issue: If the array is accessed from the callback while the sort is going on the result may be unpredictable
|
||||
// For example, the callback resizes the array in the middle of the sort
|
||||
// Possible solution: set a lock flag on the array, and prohibit modifications while the lock flag is set
|
||||
|
||||
// Bubble sort
|
||||
// TODO: optimize: Use an efficient sort algorithm
|
||||
for (asUINT i = start; i+1 < end; i++)
|
||||
{
|
||||
Copy(tmp, GetArrayItemPointer(i));
|
||||
|
||||
asUINT j = i - 1;
|
||||
|
||||
while (j != 0xFFFFFFFF && j >= start )
|
||||
asUINT best = i;
|
||||
for (asUINT j = i + 1; j < end; j++)
|
||||
{
|
||||
cmpContext->Prepare(func);
|
||||
cmpContext->SetArgAddress(0, GetDataPointer(tmp));
|
||||
cmpContext->SetArgAddress(1, At(j));
|
||||
cmpContext->SetArgAddress(0, At(j));
|
||||
cmpContext->SetArgAddress(1, At(best));
|
||||
int r = cmpContext->Execute();
|
||||
if (r != asEXECUTION_FINISHED)
|
||||
break;
|
||||
if (*(bool*)(cmpContext->GetAddressOfReturnValue()))
|
||||
{
|
||||
Copy(GetArrayItemPointer(j + 1), GetArrayItemPointer(j));
|
||||
j--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
best = j;
|
||||
}
|
||||
|
||||
Copy(GetArrayItemPointer(j + 1), tmp);
|
||||
// With Swap we guarantee that the array always sees all references
|
||||
// if the GC calls the EnumReferences in the middle of the sorting
|
||||
if( best != i )
|
||||
Swap(GetArrayItemPointer(i), GetArrayItemPointer(best));
|
||||
}
|
||||
|
||||
if (cmpContext)
|
||||
@@ -2170,8 +2182,9 @@ static void RegisterScriptArray_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectMethod("array<T>", "int findByRef(uint startAt, const T&in if_handle_then_const value) const", asFUNCTION(ScriptArrayFindByRef2_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("array<T>", "bool opEquals(const array<T>&in) const", asFUNCTION(ScriptArrayEquals_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("array<T>", "bool isEmpty() const", asFUNCTION(ScriptArrayIsEmpty_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterFuncdef("bool array<T>::less(const T&in a, const T&in b)");
|
||||
r = engine->RegisterFuncdef("bool array<T>::less(const T&in if_handle_then_const a, const T&in if_handle_then_const b)");
|
||||
r = engine->RegisterObjectMethod("array<T>", "void sort(const less &in, uint startAt = 0, uint count = uint(-1))", asFUNCTION(ScriptArraySortCallback_Generic), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
#if AS_USE_STLNAMES != 1 && AS_USE_ACCESSORS == 1
|
||||
r = engine->RegisterObjectMethod("array<T>", "uint get_length() const property", asFUNCTION(ScriptArrayLength_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("array<T>", "void set_length(uint) property", asFUNCTION(ScriptArrayResize_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
|
||||
@@ -124,6 +124,7 @@ protected:
|
||||
void *GetArrayItemPointer(int index);
|
||||
void *GetDataPointer(void *buffer);
|
||||
void Copy(void *dst, void *src);
|
||||
void Swap(void *a, void *b);
|
||||
void Precache();
|
||||
bool CheckMaxSize(asUINT numElements);
|
||||
void Resize(int delta, asUINT at);
|
||||
|
||||
@@ -302,7 +302,7 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
declaration.reserve(100);
|
||||
#endif
|
||||
|
||||
// Then check for meta data and #include directives
|
||||
// Then check for meta data and pre-processor directives
|
||||
pos = 0;
|
||||
while( pos < modifiedScript.size() )
|
||||
{
|
||||
@@ -313,10 +313,19 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
pos += len;
|
||||
continue;
|
||||
}
|
||||
string token;
|
||||
token.assign(&modifiedScript[pos], len);
|
||||
|
||||
#if AS_PROCESS_METADATA == 1
|
||||
// Check if class
|
||||
if( currentClass == "" && modifiedScript.substr(pos,len) == "class" )
|
||||
// Skip possible decorators before class and interface declarations
|
||||
if (token == "shared" || token == "abstract" || token == "mixin" || token == "external")
|
||||
{
|
||||
pos += len;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if class or interface so the metadata for members can be gathered
|
||||
if( currentClass == "" && (token == "class" || token == "interface") )
|
||||
{
|
||||
// Get the identifier after "class"
|
||||
do
|
||||
@@ -362,15 +371,15 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
}
|
||||
|
||||
// Check if end of class
|
||||
if( currentClass != "" && modifiedScript[pos] == '}' )
|
||||
if( currentClass != "" && token == "}" )
|
||||
{
|
||||
currentClass = "";
|
||||
pos += len;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if namespace
|
||||
if( modifiedScript.substr(pos,len) == "namespace" )
|
||||
// Check if namespace so the metadata for members can be gathered
|
||||
if( token == "namespace" )
|
||||
{
|
||||
// Get the identifier after "namespace"
|
||||
do
|
||||
@@ -403,7 +412,7 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
}
|
||||
|
||||
// Check if end of namespace
|
||||
if( currentNamespace != "" && modifiedScript[pos] == '}' )
|
||||
if( currentNamespace != "" && token == "}" )
|
||||
{
|
||||
size_t found = currentNamespace.rfind( "::" );
|
||||
if( found != string::npos )
|
||||
@@ -419,7 +428,7 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
}
|
||||
|
||||
// Is this the start of metadata?
|
||||
if( modifiedScript[pos] == '[' )
|
||||
if( token == "[" )
|
||||
{
|
||||
// Get the metadata string
|
||||
pos = ExtractMetadata(pos, metadata);
|
||||
@@ -438,37 +447,36 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
else
|
||||
#endif
|
||||
// Is this a preprocessor directive?
|
||||
if( modifiedScript[pos] == '#' && (pos + 1 < modifiedScript.size()) )
|
||||
if( token == "#" && (pos + 1 < modifiedScript.size()) )
|
||||
{
|
||||
int start = pos++;
|
||||
|
||||
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
|
||||
if( t == asTC_IDENTIFIER )
|
||||
if (t == asTC_IDENTIFIER)
|
||||
{
|
||||
string token;
|
||||
token.assign(&modifiedScript[pos], len);
|
||||
if( token == "include" )
|
||||
if (token == "include")
|
||||
{
|
||||
pos += len;
|
||||
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
|
||||
if( t == asTC_WHITESPACE )
|
||||
if (t == asTC_WHITESPACE)
|
||||
{
|
||||
pos += len;
|
||||
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
|
||||
}
|
||||
|
||||
if( t == asTC_VALUE && len > 2 && (modifiedScript[pos] == '"' || modifiedScript[pos] == '\'') )
|
||||
if (t == asTC_VALUE && len > 2 && (modifiedScript[pos] == '"' || modifiedScript[pos] == '\''))
|
||||
{
|
||||
// Get the include file
|
||||
string includefile;
|
||||
includefile.assign(&modifiedScript[pos+1], len-2);
|
||||
includefile.assign(&modifiedScript[pos + 1], len - 2);
|
||||
pos += len;
|
||||
|
||||
// Store it for later processing
|
||||
includes.push_back(includefile);
|
||||
|
||||
// Overwrite the include directive with space characters to avoid compiler error
|
||||
OverwriteCode(start, pos-start);
|
||||
OverwriteCode(start, pos - start);
|
||||
}
|
||||
}
|
||||
else if (token == "pragma")
|
||||
@@ -491,6 +499,19 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
|
||||
OverwriteCode(start, pos - start);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for lines starting with #!, e.g. shebang interpreter directive. These will be treated as comments and removed by the preprocessor
|
||||
if (modifiedScript[pos] == '!')
|
||||
{
|
||||
// Read until the end of the line
|
||||
pos += len;
|
||||
for (; pos < modifiedScript.size() && modifiedScript[pos] != '\n'; pos++);
|
||||
|
||||
// Overwrite the directive with space characters to avoid compiler error
|
||||
OverwriteCode(start, pos - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't search for metadata/includes within statement blocks or between tokens in statements
|
||||
else
|
||||
|
||||
@@ -1140,7 +1140,6 @@ void RegisterScriptDictionary_Native(asIScriptEngine *engine)
|
||||
// Same as deleteAll
|
||||
r = engine->RegisterObjectMethod("dictionary", "void clear()", asMETHOD(CScriptDictionary,DeleteAll), asCALL_THISCALL); assert( r >= 0 );
|
||||
#endif
|
||||
(void)r;
|
||||
|
||||
// Cache some things the dictionary will need at runtime
|
||||
SDictionaryCache::Setup(engine);
|
||||
@@ -1209,7 +1208,6 @@ void RegisterScriptDictionary_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectBehaviour("dictionary", asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptDictionaryEnumReferences_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectBehaviour("dictionary", asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptDictionaryReleaseAllReferences_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
|
||||
(void)r;
|
||||
// Cache some things the dictionary will need at runtime
|
||||
SDictionaryCache::Setup(engine);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "scriptfilesystem.h"
|
||||
#include "../autowrapper/aswrappedcall.h"
|
||||
#include <string.h> // strstr()
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <direct.h> // _getcwd
|
||||
@@ -383,6 +384,7 @@ asINT64 CScriptFileSystem::GetSize(const string &path) const
|
||||
// - path not found
|
||||
// - access denied
|
||||
// TODO: Should be able to define the permissions for the directory
|
||||
// TODO: Should support recursively creating directories
|
||||
int CScriptFileSystem::MakeDir(const string &path)
|
||||
{
|
||||
string search;
|
||||
|
||||
@@ -222,9 +222,8 @@ void CScriptHandle::EnumReferences(asIScriptEngine *inEngine)
|
||||
inEngine->GCEnumCallback(m_type);
|
||||
}
|
||||
|
||||
void CScriptHandle::ReleaseReferences(asIScriptEngine *inEngine)
|
||||
void CScriptHandle::ReleaseReferences(asIScriptEngine * /*inEngine*/)
|
||||
{
|
||||
(void)inEngine;
|
||||
// Simply clear the content to release the references
|
||||
Set(0, 0);
|
||||
}
|
||||
@@ -250,7 +249,6 @@ void RegisterScriptHandle_Native(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ?&in)", asMETHOD(CScriptHandle, Assign), asCALL_THISCALL); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asMETHODPR(CScriptHandle, operator==, (const CScriptHandle &) const, bool), asCALL_THISCALL); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asMETHODPR(CScriptHandle, Equals, (void*, int) const, bool), asCALL_THISCALL); assert( r >= 0 );
|
||||
(void)r;
|
||||
}
|
||||
|
||||
void CScriptHandle_Construct_Generic(asIScriptGeneric *gen)
|
||||
@@ -348,7 +346,6 @@ void RegisterScriptHandle_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ?&in)", asFUNCTION(CScriptHandle_AssignVar_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asFUNCTION(CScriptHandle_Equals_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asFUNCTION(CScriptHandle_EqualsVar_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
(void)r;
|
||||
}
|
||||
|
||||
void RegisterScriptHandle(asIScriptEngine *engine)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <stdlib.h>
|
||||
#include "../autowrapper/aswrappedcall.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -980,9 +981,16 @@ void RegisterExceptionRoutines(asIScriptEngine *engine)
|
||||
// The string type must be available
|
||||
assert(engine->GetTypeInfoByDecl("string"));
|
||||
|
||||
r = engine->RegisterGlobalFunction("void throw(const string &in)", asFUNCTION(ScriptThrow), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string getExceptionInfo()", asFUNCTION(ScriptGetExceptionInfo), asCALL_CDECL); assert(r >= 0);
|
||||
(void)r;
|
||||
if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") == 0)
|
||||
{
|
||||
r = engine->RegisterGlobalFunction("void throw(const string &in)", asFUNCTION(ScriptThrow), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string getExceptionInfo()", asFUNCTION(ScriptGetExceptionInfo), asCALL_CDECL); assert(r >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = engine->RegisterGlobalFunction("void throw(const string &in)", WRAP_FN(ScriptThrow), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string getExceptionInfo()", WRAP_FN(ScriptGetExceptionInfo), asCALL_GENERIC); assert(r >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
END_AS_NAMESPACE
|
||||
|
||||
@@ -72,45 +72,27 @@ double fraction(double v)
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T, typename F>
|
||||
struct alias_cast_t
|
||||
{
|
||||
union
|
||||
{
|
||||
F raw;
|
||||
T data;
|
||||
};
|
||||
};
|
||||
|
||||
// As AngelScript doesn't allow bitwise manipulation of float types we'll provide a couple of
|
||||
// functions for converting float values to IEEE 754 formatted values etc. This also allow us to
|
||||
// provide a platform agnostic representation to the script so the scripts don't have to worry
|
||||
// about whether the CPU uses IEEE 754 floats or some other representation
|
||||
float fpFromIEEE(asUINT raw)
|
||||
{
|
||||
// TODO: Identify CPU family to provide proper conversion
|
||||
// if the CPU doesn't natively use IEEE style floats
|
||||
alias_cast_t<asUINT, float> t;
|
||||
t.raw = raw;
|
||||
return t.data;
|
||||
// TODO: Identify CPU family to provide proper conversion
|
||||
// if the CPU doesn't natively use IEEE style floats
|
||||
return *reinterpret_cast<float*>(&raw);
|
||||
}
|
||||
asUINT fpToIEEE(float fp)
|
||||
{
|
||||
alias_cast_t<float, asUINT> t;
|
||||
t.raw = fp;
|
||||
return t.data;
|
||||
return *reinterpret_cast<asUINT*>(&fp);
|
||||
}
|
||||
double fpFromIEEE(asQWORD raw)
|
||||
{
|
||||
alias_cast_t<asQWORD, double> t;
|
||||
t.raw = raw;
|
||||
return t.data;
|
||||
return *reinterpret_cast<double*>(&raw);
|
||||
}
|
||||
asQWORD fpToIEEE(double fp)
|
||||
{
|
||||
alias_cast_t<double, asQWORD> t;
|
||||
t.raw = fp;
|
||||
return t.data;
|
||||
return *reinterpret_cast<asQWORD*>(&fp);
|
||||
}
|
||||
|
||||
// closeTo() is used to determine if the binary representation of two numbers are
|
||||
@@ -214,7 +196,6 @@ void RegisterScriptMath_Native(asIScriptEngine *engine)
|
||||
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTIONPR(floor, (double), double), asCALL_CDECL); assert( r >= 0 );
|
||||
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTIONPR(fraction, (double), double), asCALL_CDECL); assert( r >= 0 );
|
||||
#endif
|
||||
(void)r;
|
||||
}
|
||||
|
||||
#if AS_USE_FLOAT
|
||||
@@ -351,7 +332,6 @@ void RegisterScriptMath_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTION(floor_generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTION(fraction_generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
#endif
|
||||
(void)r;
|
||||
}
|
||||
|
||||
void RegisterScriptMath(asIScriptEngine *engine)
|
||||
|
||||
@@ -34,8 +34,9 @@ static CScriptArray *StringSplit(const string &delim, const string &str)
|
||||
CScriptArray *array = CScriptArray::Create(arrayType);
|
||||
|
||||
// Find the existence of the delimiter in the input string
|
||||
int pos = 0, prev = 0, count = 0;
|
||||
while( (pos = (int)str.find(delim, prev)) != (int)string::npos )
|
||||
size_t pos = 0, prev = 0;
|
||||
asUINT count = 0;
|
||||
while( (pos = str.find(delim, prev)) != string::npos )
|
||||
{
|
||||
// Add the part to the array
|
||||
array->Resize(array->GetSize()+1);
|
||||
@@ -43,7 +44,7 @@ static CScriptArray *StringSplit(const string &delim, const string &str)
|
||||
|
||||
// Find the next part
|
||||
count++;
|
||||
prev = pos + (int)delim.length();
|
||||
prev = pos + delim.length();
|
||||
}
|
||||
|
||||
// Add the remaining part
|
||||
|
||||
@@ -226,7 +226,7 @@ void RegisterScriptWeakRef_Native(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectType("weakref<class T>", sizeof(CScriptWeakRef), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS_DAK); assert( r >= 0 );
|
||||
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptWeakRefConstruct), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, T@+)", asFUNCTION(ScriptWeakRefConstruct2), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, T@+) explicit", asFUNCTION(ScriptWeakRefConstruct2), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ScriptWeakRefDestruct), asCALL_CDECL_OBJLAST); assert( r >= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&in, bool&out)", asFUNCTION(ScriptWeakRefTemplateCallback), asCALL_CDECL); assert( r >= 0 );
|
||||
|
||||
@@ -242,7 +242,7 @@ void RegisterScriptWeakRef_Native(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectType("const_weakref<class T>", sizeof(CScriptWeakRef), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS_DAK); assert( r >= 0 );
|
||||
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptWeakRefConstruct), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, const T@+)", asFUNCTION(ScriptWeakRefConstruct2), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, const T@+) explicit", asFUNCTION(ScriptWeakRefConstruct2), asCALL_CDECL_OBJLAST); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ScriptWeakRefDestruct), asCALL_CDECL_OBJLAST); assert( r >= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&in, bool&out)", asFUNCTION(ScriptWeakRefTemplateCallback), asCALL_CDECL); assert( r >= 0 );
|
||||
|
||||
@@ -332,7 +332,7 @@ void RegisterScriptWeakRef_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectType("weakref<class T>", sizeof(CScriptWeakRef), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS_DAK); assert( r >= 0 );
|
||||
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptWeakRefConstruct_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, T@+)", asFUNCTION(ScriptWeakRefConstruct2_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, T@+) explicit", asFUNCTION(ScriptWeakRefConstruct2_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&in, bool&out)", asFUNCTION(ScriptWeakRefTemplateCallback_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectBehaviour("weakref<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ScriptWeakRefDestruct_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
|
||||
@@ -348,7 +348,7 @@ void RegisterScriptWeakRef_Generic(asIScriptEngine *engine)
|
||||
r = engine->RegisterObjectType("const_weakref<class T>", sizeof(CScriptWeakRef), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS_DAK); assert( r >= 0 );
|
||||
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptWeakRefConstruct_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, const T@+)", asFUNCTION(ScriptWeakRefConstruct2_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_CONSTRUCT, "void f(int&in, const T@+) explicit", asFUNCTION(ScriptWeakRefConstruct2_Generic), asCALL_GENERIC); assert( r>= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&in, bool&out)", asFUNCTION(ScriptWeakRefTemplateCallback_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterObjectBehaviour("const_weakref<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ScriptWeakRefDestruct_Generic), asCALL_GENERIC); assert( r >= 0 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user