|
@@ -51,6 +51,7 @@
|
|
|
#include "as_generic.h"
|
|
#include "as_generic.h"
|
|
|
#include "as_scriptobject.h"
|
|
#include "as_scriptobject.h"
|
|
|
#include "as_compiler.h"
|
|
#include "as_compiler.h"
|
|
|
|
|
+#include "as_bytecode.h"
|
|
|
|
|
|
|
|
BEGIN_AS_NAMESPACE
|
|
BEGIN_AS_NAMESPACE
|
|
|
|
|
|
|
@@ -206,10 +207,13 @@ AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version)
|
|
|
// Verify endianess
|
|
// Verify endianess
|
|
|
#ifdef AS_BIG_ENDIAN
|
|
#ifdef AS_BIG_ENDIAN
|
|
|
asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x00010203 );
|
|
asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x00010203 );
|
|
|
- asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == I64(0x0001020304050607) );
|
|
|
|
|
|
|
+ asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == ((asQWORD(0x00010203)<<32)|asQWORD(0x04050607)) );
|
|
|
#else
|
|
#else
|
|
|
asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x03020100 );
|
|
asASSERT( *(asDWORD*)"\x00\x01\x02\x03" == 0x03020100 );
|
|
|
- asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == I64(0x0706050403020100) );
|
|
|
|
|
|
|
+ // C++ didn't have a standard way of declaring 64bit literal constants until C++11, so
|
|
|
|
|
+ // I'm forced to do it like this to avoid compilers warnings when compiling with the full
|
|
|
|
|
+ // C++ compliance.
|
|
|
|
|
+ asASSERT( *(asQWORD*)"\x00\x01\x02\x03\x04\x05\x06\x07" == ((asQWORD(0x07060504)<<32)|asQWORD(0x03020100)) );
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
return asNEW(asCScriptEngine)();
|
|
return asNEW(asCScriptEngine)();
|
|
@@ -448,7 +452,8 @@ asCScriptEngine::asCScriptEngine()
|
|
|
scriptFunctions.PushLast(0);
|
|
scriptFunctions.PushLast(0);
|
|
|
|
|
|
|
|
// Make sure typeId for the built-in primitives are defined according to asETypeIdFlags
|
|
// Make sure typeId for the built-in primitives are defined according to asETypeIdFlags
|
|
|
- int id;
|
|
|
|
|
|
|
+ int id = 0;
|
|
|
|
|
+ UNUSED_VAR(id); // It is only used in debug mode
|
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttVoid, false)); asASSERT( id == asTYPEID_VOID );
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttVoid, false)); asASSERT( id == asTYPEID_VOID );
|
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttBool, false)); asASSERT( id == asTYPEID_BOOL );
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttBool, false)); asASSERT( id == asTYPEID_BOOL );
|
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttInt8, false)); asASSERT( id == asTYPEID_INT8 );
|
|
id = GetTypeIdFromDataType(asCDataType::CreatePrimitive(ttInt8, false)); asASSERT( id == asTYPEID_INT8 );
|
|
@@ -691,6 +696,38 @@ int asCScriptEngine::Release() const
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// interface
|
|
|
|
|
+int asCScriptEngine::SetDefaultNamespace(const char *nameSpace)
|
|
|
|
|
+{
|
|
|
|
|
+ if( nameSpace == 0 )
|
|
|
|
|
+ return ConfigError(asINVALID_ARG, "SetDefaultNamespace", nameSpace, 0);
|
|
|
|
|
+
|
|
|
|
|
+ defaultNamespace = nameSpace;
|
|
|
|
|
+ if( defaultNamespace != "" )
|
|
|
|
|
+ {
|
|
|
|
|
+ // Make sure the namespace is composed of alternating identifier and ::
|
|
|
|
|
+ size_t pos = 0;
|
|
|
|
|
+ bool expectIdentifier = true;
|
|
|
|
|
+ size_t len;
|
|
|
|
|
+ eTokenType t = ttIdentifier;
|
|
|
|
|
+
|
|
|
|
|
+ for( ; pos < defaultNamespace.GetLength(); pos += len)
|
|
|
|
|
+ {
|
|
|
|
|
+ t = tok.GetToken(defaultNamespace.AddressOf() + pos, defaultNamespace.GetLength() - pos, &len);
|
|
|
|
|
+ if( (expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope) )
|
|
|
|
|
+ return ConfigError(asINVALID_DECLARATION, "SetDefaultNamespace", nameSpace, 0);
|
|
|
|
|
+
|
|
|
|
|
+ expectIdentifier = !expectIdentifier;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // If the namespace ends with :: then strip it off
|
|
|
|
|
+ if( t == ttScope )
|
|
|
|
|
+ defaultNamespace.SetLength(defaultNamespace.GetLength()-2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// interface
|
|
// interface
|
|
|
void *asCScriptEngine::SetUserData(void *data)
|
|
void *asCScriptEngine::SetUserData(void *data)
|
|
|
{
|
|
{
|
|
@@ -830,6 +867,7 @@ int asCScriptEngine::DiscardModule(const char *module)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// internal
|
|
|
void asCScriptEngine::ClearUnusedTypes()
|
|
void asCScriptEngine::ClearUnusedTypes()
|
|
|
{
|
|
{
|
|
|
// Build a list of all types to check for
|
|
// Build a list of all types to check for
|
|
@@ -938,6 +976,7 @@ void asCScriptEngine::ClearUnusedTypes()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// internal
|
|
|
void asCScriptEngine::RemoveTypeAndRelatedFromList(asCArray<asCObjectType*> &types, asCObjectType *ot)
|
|
void asCScriptEngine::RemoveTypeAndRelatedFromList(asCArray<asCObjectType*> &types, asCObjectType *ot)
|
|
|
{
|
|
{
|
|
|
// Remove the type from the list
|
|
// Remove the type from the list
|
|
@@ -1037,7 +1076,7 @@ int asCScriptEngine::GetMethodIdByDecl(const asCObjectType *ot, const char *decl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-// Internal
|
|
|
|
|
|
|
+// internal
|
|
|
asCString asCScriptEngine::GetFunctionDeclaration(int funcId)
|
|
asCString asCScriptEngine::GetFunctionDeclaration(int funcId)
|
|
|
{
|
|
{
|
|
|
asCString str;
|
|
asCString str;
|
|
@@ -1048,6 +1087,7 @@ asCString asCScriptEngine::GetFunctionDeclaration(int funcId)
|
|
|
return str;
|
|
return str;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// internal
|
|
|
asCScriptFunction *asCScriptEngine::GetScriptFunction(int funcId) const
|
|
asCScriptFunction *asCScriptEngine::GetScriptFunction(int funcId) const
|
|
|
{
|
|
{
|
|
|
if( funcId < 0 || funcId >= (int)scriptFunctions.GetLength() )
|
|
if( funcId < 0 || funcId >= (int)scriptFunctions.GetLength() )
|
|
@@ -1057,7 +1097,7 @@ asCScriptFunction *asCScriptEngine::GetScriptFunction(int funcId) const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+// interface
|
|
|
asIScriptContext *asCScriptEngine::CreateContext()
|
|
asIScriptContext *asCScriptEngine::CreateContext()
|
|
|
{
|
|
{
|
|
|
asIScriptContext *ctx = 0;
|
|
asIScriptContext *ctx = 0;
|
|
@@ -1065,6 +1105,7 @@ asIScriptContext *asCScriptEngine::CreateContext()
|
|
|
return ctx;
|
|
return ctx;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// internal
|
|
|
int asCScriptEngine::CreateContext(asIScriptContext **context, bool isInternal)
|
|
int asCScriptEngine::CreateContext(asIScriptContext **context, bool isInternal)
|
|
|
{
|
|
{
|
|
|
*context = asNEW(asCContext)(this, !isInternal);
|
|
*context = asNEW(asCContext)(this, !isInternal);
|
|
@@ -1082,7 +1123,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara
|
|
|
int r;
|
|
int r;
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
- r = bld.ParseDataType(obj, &dt);
|
|
|
|
|
|
|
+ r = bld.ParseDataType(obj, &dt, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return ConfigError(r, "RegisterObjectProperty", obj, declaration);
|
|
return ConfigError(r, "RegisterObjectProperty", obj, declaration);
|
|
|
|
|
|
|
@@ -1114,6 +1155,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara
|
|
|
return asSUCCESS;
|
|
return asSUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// interface
|
|
|
int asCScriptEngine::RegisterInterface(const char *name)
|
|
int asCScriptEngine::RegisterInterface(const char *name)
|
|
|
{
|
|
{
|
|
|
if( name == 0 ) return ConfigError(asINVALID_NAME, "RegisterInterface", 0, 0);
|
|
if( name == 0 ) return ConfigError(asINVALID_NAME, "RegisterInterface", 0, 0);
|
|
@@ -1122,7 +1164,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
|
|
|
asUINT n;
|
|
asUINT n;
|
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
|
{
|
|
{
|
|
|
- if( objectTypes[n] && objectTypes[n]->name == name )
|
|
|
|
|
|
|
+ if( objectTypes[n] && objectTypes[n]->name == name && objectTypes[n]->nameSpace == defaultNamespace )
|
|
|
return asALREADY_REGISTERED;
|
|
return asALREADY_REGISTERED;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1130,7 +1172,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
|
- int r = bld.ParseDataType(name, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(name, &dt, defaultNamespace);
|
|
|
msgCallback = oldMsgCallback;
|
|
msgCallback = oldMsgCallback;
|
|
|
if( r >= 0 ) return ConfigError(asERROR, "RegisterInterface", name, 0);
|
|
if( r >= 0 ) return ConfigError(asERROR, "RegisterInterface", name, 0);
|
|
|
|
|
|
|
@@ -1153,6 +1195,7 @@ int asCScriptEngine::RegisterInterface(const char *name)
|
|
|
st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED;
|
|
st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED;
|
|
|
st->size = 0; // Cannot be instanciated
|
|
st->size = 0; // Cannot be instanciated
|
|
|
st->name = name;
|
|
st->name = name;
|
|
|
|
|
+ st->nameSpace = defaultNamespace;
|
|
|
|
|
|
|
|
// Use the default script class behaviours
|
|
// Use the default script class behaviours
|
|
|
st->beh.factory = 0;
|
|
st->beh.factory = 0;
|
|
@@ -1179,7 +1222,7 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla
|
|
|
|
|
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
- int r = bld.ParseDataType(intf, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(intf, &dt, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return ConfigError(r, "RegisterInterfaceMethod", intf, declaration);
|
|
return ConfigError(r, "RegisterInterfaceMethod", intf, declaration);
|
|
|
|
|
|
|
@@ -1239,22 +1282,24 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
|
|
|
if( flags & asOBJ_REF )
|
|
if( flags & asOBJ_REF )
|
|
|
{
|
|
{
|
|
|
// Can optionally have the asOBJ_GC, asOBJ_NOHANDLE, asOBJ_SCOPED, or asOBJ_TEMPLATE flag set, but nothing else
|
|
// Can optionally have the asOBJ_GC, asOBJ_NOHANDLE, asOBJ_SCOPED, or asOBJ_TEMPLATE flag set, but nothing else
|
|
|
- if( flags & ~(asOBJ_REF | asOBJ_GC | asOBJ_NOHANDLE | asOBJ_SCOPED | asOBJ_TEMPLATE) )
|
|
|
|
|
|
|
+ if( flags & ~(asOBJ_REF | asOBJ_GC | asOBJ_NOHANDLE | asOBJ_SCOPED | asOBJ_TEMPLATE | asOBJ_NOCOUNT) )
|
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
|
|
|
|
|
// flags are exclusive
|
|
// flags are exclusive
|
|
|
- if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE|asOBJ_SCOPED)) )
|
|
|
|
|
|
|
+ if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE|asOBJ_SCOPED|asOBJ_NOCOUNT)) )
|
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
- if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC|asOBJ_SCOPED)) )
|
|
|
|
|
|
|
+ if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC|asOBJ_SCOPED|asOBJ_NOCOUNT)) )
|
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
- if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC|asOBJ_NOHANDLE)) )
|
|
|
|
|
|
|
+ if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_NOCOUNT)) )
|
|
|
|
|
+ return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
|
|
+ if( (flags & asOBJ_NOCOUNT) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_SCOPED)) )
|
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
}
|
|
}
|
|
|
else if( flags & asOBJ_VALUE )
|
|
else if( flags & asOBJ_VALUE )
|
|
|
{
|
|
{
|
|
|
// Cannot use reference flags
|
|
// Cannot use reference flags
|
|
|
// TODO: template: Should be possible to register a value type as template type
|
|
// TODO: template: Should be possible to register a value type as template type
|
|
|
- if( flags & (asOBJ_REF | asOBJ_GC | asOBJ_SCOPED | asOBJ_TEMPLATE) )
|
|
|
|
|
|
|
+ if( flags & (asOBJ_REF | asOBJ_GC | asOBJ_SCOPED | asOBJ_TEMPLATE | asOBJ_NOCOUNT) )
|
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0);
|
|
|
|
|
|
|
|
// flags are exclusive
|
|
// flags are exclusive
|
|
@@ -1336,13 +1381,14 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
|
|
|
asUINT n;
|
|
asUINT n;
|
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
|
{
|
|
{
|
|
|
- if( objectTypes[n] && objectTypes[n]->name == typeName )
|
|
|
|
|
|
|
+ if( objectTypes[n] && objectTypes[n]->name == typeName && objectTypes[n]->nameSpace == defaultNamespace )
|
|
|
// This is not an irrepairable error, as it may just be that the same type is registered twice
|
|
// This is not an irrepairable error, as it may just be that the same type is registered twice
|
|
|
return asALREADY_REGISTERED;
|
|
return asALREADY_REGISTERED;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
|
type->name = typeName;
|
|
type->name = typeName;
|
|
|
|
|
+ type->nameSpace = defaultNamespace;
|
|
|
type->size = byteSize;
|
|
type->size = byteSize;
|
|
|
type->flags = flags;
|
|
type->flags = flags;
|
|
|
type->accessMask = defaultAccessMask;
|
|
type->accessMask = defaultAccessMask;
|
|
@@ -1405,7 +1451,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
|
|
|
// Use builder to parse the datatype
|
|
// Use builder to parse the datatype
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
|
- r = bld.ParseDataType(name, &dt);
|
|
|
|
|
|
|
+ r = bld.ParseDataType(name, &dt, defaultNamespace);
|
|
|
msgCallback = oldMsgCallback;
|
|
msgCallback = oldMsgCallback;
|
|
|
|
|
|
|
|
// If the builder fails, then the type name
|
|
// If the builder fails, then the type name
|
|
@@ -1429,6 +1475,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
|
|
|
// Put the data type in the list
|
|
// Put the data type in the list
|
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
|
type->name = typeName;
|
|
type->name = typeName;
|
|
|
|
|
+ type->nameSpace = defaultNamespace;
|
|
|
type->size = byteSize;
|
|
type->size = byteSize;
|
|
|
type->flags = flags;
|
|
type->flags = flags;
|
|
|
type->accessMask = defaultAccessMask;
|
|
type->accessMask = defaultAccessMask;
|
|
@@ -1467,6 +1514,8 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asDWORD
|
|
|
// Put the data type in the list
|
|
// Put the data type in the list
|
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
asCObjectType *type = asNEW(asCObjectType)(this);
|
|
|
type->name = dt.GetObjectType()->name;
|
|
type->name = dt.GetObjectType()->name;
|
|
|
|
|
+ // The namespace will be the same as the original template type
|
|
|
|
|
+ type->nameSpace = dt.GetObjectType()->nameSpace;
|
|
|
type->templateSubType = dt.GetSubType();
|
|
type->templateSubType = dt.GetSubType();
|
|
|
if( type->templateSubType.GetObjectType() ) type->templateSubType.GetObjectType()->AddRef();
|
|
if( type->templateSubType.GetObjectType() ) type->templateSubType.GetObjectType()->AddRef();
|
|
|
type->size = byteSize;
|
|
type->size = byteSize;
|
|
@@ -1497,7 +1546,7 @@ int asCScriptEngine::RegisterObjectBehaviour(const char *datatype, asEBehaviours
|
|
|
// Determine the object type
|
|
// Determine the object type
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
asCDataType type;
|
|
asCDataType type;
|
|
|
- int r = bld.ParseDataType(datatype, &type);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(datatype, &type, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return ConfigError(r, "RegisterObjectBehaviour", datatype, decl);
|
|
return ConfigError(r, "RegisterObjectBehaviour", datatype, decl);
|
|
|
|
|
|
|
@@ -1719,7 +1768,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as
|
|
|
// Must be a ref type and must not have asOBJ_NOHANDLE, nor asOBJ_SCOPED
|
|
// Must be a ref type and must not have asOBJ_NOHANDLE, nor asOBJ_SCOPED
|
|
|
if( !(func.objectType->flags & asOBJ_REF) ||
|
|
if( !(func.objectType->flags & asOBJ_REF) ||
|
|
|
(func.objectType->flags & asOBJ_NOHANDLE) ||
|
|
(func.objectType->flags & asOBJ_NOHANDLE) ||
|
|
|
- (func.objectType->flags & asOBJ_SCOPED) )
|
|
|
|
|
|
|
+ (func.objectType->flags & asOBJ_SCOPED) ||
|
|
|
|
|
+ (func.objectType->flags & asOBJ_NOCOUNT) )
|
|
|
{
|
|
{
|
|
|
WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
|
|
WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
|
|
|
return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
|
|
return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
|
|
@@ -1741,7 +1791,9 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as
|
|
|
else if( behaviour == asBEHAVE_RELEASE )
|
|
else if( behaviour == asBEHAVE_RELEASE )
|
|
|
{
|
|
{
|
|
|
// Must be a ref type and must not have asOBJ_NOHANDLE
|
|
// Must be a ref type and must not have asOBJ_NOHANDLE
|
|
|
- if( !(func.objectType->flags & asOBJ_REF) || (func.objectType->flags & asOBJ_NOHANDLE) )
|
|
|
|
|
|
|
+ if( !(func.objectType->flags & asOBJ_REF) ||
|
|
|
|
|
+ (func.objectType->flags & asOBJ_NOHANDLE) ||
|
|
|
|
|
+ (func.objectType->flags & asOBJ_NOCOUNT) )
|
|
|
{
|
|
{
|
|
|
WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
|
|
WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE);
|
|
|
return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
|
|
return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
|
|
@@ -1963,8 +2015,7 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point
|
|
|
|
|
|
|
|
int r;
|
|
int r;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
- // TODO: namespace: Use proper namespace
|
|
|
|
|
- if( (r = bld.VerifyProperty(0, declaration, name, type, "")) < 0 )
|
|
|
|
|
|
|
+ if( (r = bld.VerifyProperty(0, declaration, name, type, defaultNamespace)) < 0 )
|
|
|
return ConfigError(r, "RegisterGlobalProperty", declaration, 0);
|
|
return ConfigError(r, "RegisterGlobalProperty", declaration, 0);
|
|
|
|
|
|
|
|
// Don't allow registering references as global properties
|
|
// Don't allow registering references as global properties
|
|
@@ -1974,6 +2025,7 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point
|
|
|
// Store the property info
|
|
// Store the property info
|
|
|
asCGlobalProperty *prop = AllocateGlobalProperty();
|
|
asCGlobalProperty *prop = AllocateGlobalProperty();
|
|
|
prop->name = name;
|
|
prop->name = name;
|
|
|
|
|
+ prop->nameSpace = defaultNamespace;
|
|
|
prop->type = type;
|
|
prop->type = type;
|
|
|
prop->accessMask = defaultAccessMask;
|
|
prop->accessMask = defaultAccessMask;
|
|
|
|
|
|
|
@@ -2032,13 +2084,15 @@ asUINT asCScriptEngine::GetGlobalPropertyCount() const
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
// TODO: If the typeId ever encodes the const flag, then the isConst parameter should be removed
|
|
// TODO: If the typeId ever encodes the const flag, then the isConst parameter should be removed
|
|
|
-int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId, bool *isConst, const char **configGroup, void **pointer) const
|
|
|
|
|
|
|
+int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace, int *typeId, bool *isConst, const char **configGroup, void **pointer, asDWORD *accessMask) const
|
|
|
{
|
|
{
|
|
|
if( index >= registeredGlobalProps.GetLength() )
|
|
if( index >= registeredGlobalProps.GetLength() )
|
|
|
return asINVALID_ARG;
|
|
return asINVALID_ARG;
|
|
|
|
|
|
|
|
if( name )
|
|
if( name )
|
|
|
*name = registeredGlobalProps[index]->name.AddressOf();
|
|
*name = registeredGlobalProps[index]->name.AddressOf();
|
|
|
|
|
+ if( nameSpace )
|
|
|
|
|
+ *nameSpace = registeredGlobalProps[index]->nameSpace.AddressOf();
|
|
|
|
|
|
|
|
if( configGroup )
|
|
if( configGroup )
|
|
|
{
|
|
{
|
|
@@ -2058,9 +2112,61 @@ int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, i
|
|
|
if( pointer )
|
|
if( pointer )
|
|
|
*pointer = registeredGlobalProps[index]->GetRegisteredAddress();
|
|
*pointer = registeredGlobalProps[index]->GetRegisteredAddress();
|
|
|
|
|
|
|
|
|
|
+ if( accessMask )
|
|
|
|
|
+ *accessMask = registeredGlobalProps[index]->accessMask;
|
|
|
|
|
+
|
|
|
return asSUCCESS;
|
|
return asSUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// interface
|
|
|
|
|
+int asCScriptEngine::GetGlobalPropertyIndexByName(const char *name) const
|
|
|
|
|
+{
|
|
|
|
|
+ // Find the global var id
|
|
|
|
|
+ int id = -1;
|
|
|
|
|
+ for( size_t n = 0; n < registeredGlobalProps.GetLength(); n++ )
|
|
|
|
|
+ {
|
|
|
|
|
+ if( registeredGlobalProps[n]->name == name &&
|
|
|
|
|
+ registeredGlobalProps[n]->nameSpace == defaultNamespace )
|
|
|
|
|
+ {
|
|
|
|
|
+ id = (int)n;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if( id == -1 ) return asNO_GLOBAL_VAR;
|
|
|
|
|
+
|
|
|
|
|
+ return id;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// interface
|
|
|
|
|
+int asCScriptEngine::GetGlobalPropertyIndexByDecl(const char *decl) const
|
|
|
|
|
+{
|
|
|
|
|
+ // This const cast is OK. The builder won't modify the engine
|
|
|
|
|
+ asCBuilder bld(const_cast<asCScriptEngine*>(this), 0);
|
|
|
|
|
+
|
|
|
|
|
+ asCString name, ns;
|
|
|
|
|
+ asCDataType dt;
|
|
|
|
|
+ bld.ParseVariableDeclaration(decl, defaultNamespace, name, ns, dt);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: optimize: Improve linear search
|
|
|
|
|
+ // Search for a match
|
|
|
|
|
+ int id = -1;
|
|
|
|
|
+ for( size_t n = 0; n < registeredGlobalProps.GetLength(); ++n )
|
|
|
|
|
+ {
|
|
|
|
|
+ if( name == registeredGlobalProps[n]->name &&
|
|
|
|
|
+ dt == registeredGlobalProps[n]->type &&
|
|
|
|
|
+ ns == registeredGlobalProps[n]->nameSpace )
|
|
|
|
|
+ {
|
|
|
|
|
+ id = (int)n;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if( id == -1 ) return asNO_GLOBAL_VAR;
|
|
|
|
|
+
|
|
|
|
|
+ return id;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// interface
|
|
// interface
|
|
|
int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv)
|
|
int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv)
|
|
|
{
|
|
{
|
|
@@ -2070,7 +2176,7 @@ int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declarati
|
|
|
// Determine the object type
|
|
// Determine the object type
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
- int r = bld.ParseDataType(obj, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(obj, &dt, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return ConfigError(r, "RegisterObjectMethod", obj, declaration);
|
|
return ConfigError(r, "RegisterObjectMethod", obj, declaration);
|
|
|
|
|
|
|
@@ -2221,9 +2327,11 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu
|
|
|
return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0);
|
|
return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // TODO: namespace: What if the declaration defined an explicit namespace?
|
|
|
|
|
+ func->nameSpace = defaultNamespace;
|
|
|
|
|
+
|
|
|
// Check name conflicts
|
|
// Check name conflicts
|
|
|
- // TODO: namespace: Allow application to specify namespace. Probably with a SetDefaultNamespace
|
|
|
|
|
- r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, "");
|
|
|
|
|
|
|
+ r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
{
|
|
{
|
|
|
asDELETE(func,asCScriptFunction);
|
|
asDELETE(func,asCScriptFunction);
|
|
@@ -2393,7 +2501,8 @@ void asCScriptEngine::PrepareEngine()
|
|
|
}
|
|
}
|
|
|
// Verify that ref types have add ref and release behaviours
|
|
// Verify that ref types have add ref and release behaviours
|
|
|
else if( (objectTypes[n]->flags & asOBJ_REF) &&
|
|
else if( (objectTypes[n]->flags & asOBJ_REF) &&
|
|
|
- !(objectTypes[n]->flags & asOBJ_NOHANDLE) )
|
|
|
|
|
|
|
+ !(objectTypes[n]->flags & asOBJ_NOHANDLE) &&
|
|
|
|
|
+ !(objectTypes[n]->flags & asOBJ_NOCOUNT) )
|
|
|
{
|
|
{
|
|
|
if( objectTypes[n]->beh.addref == 0 ||
|
|
if( objectTypes[n]->beh.addref == 0 ||
|
|
|
objectTypes[n]->beh.release == 0 )
|
|
objectTypes[n]->beh.release == 0 )
|
|
@@ -2454,7 +2563,7 @@ int asCScriptEngine::RegisterDefaultArrayType(const char *type)
|
|
|
{
|
|
{
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
- int r = bld.ParseDataType(type, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(type, &dt, defaultNamespace);
|
|
|
if( r < 0 ) return r;
|
|
if( r < 0 ) return r;
|
|
|
|
|
|
|
|
if( dt.GetObjectType() == 0 ||
|
|
if( dt.GetObjectType() == 0 ||
|
|
@@ -2504,7 +2613,7 @@ int asCScriptEngine::RegisterStringFactory(const char *datatype, const asSFuncPt
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
|
|
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
- r = bld.ParseDataType(datatype, &dt);
|
|
|
|
|
|
|
+ r = bld.ParseDataType(datatype, &dt, defaultNamespace, true);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
{
|
|
{
|
|
|
// Set as dummy before deleting
|
|
// Set as dummy before deleting
|
|
@@ -2862,9 +2971,25 @@ asCScriptFunction *asCScriptEngine::GenerateTemplateFactoryStub(asCObjectType *t
|
|
|
|
|
|
|
|
SetScriptFunction(func);
|
|
SetScriptFunction(func);
|
|
|
|
|
|
|
|
- asCBuilder builder(this, 0);
|
|
|
|
|
- asCCompiler compiler(this);
|
|
|
|
|
- compiler.CompileTemplateFactoryStub(&builder, factoryId, ot, func);
|
|
|
|
|
|
|
+ // Generate the bytecode for the factory stub
|
|
|
|
|
+ func->byteCode.SetLength(asBCTypeSize[asBCInfo[asBC_OBJTYPE].type] +
|
|
|
|
|
+ asBCTypeSize[asBCInfo[asBC_CALLSYS].type] +
|
|
|
|
|
+ asBCTypeSize[asBCInfo[asBC_RET].type]);
|
|
|
|
|
+ asDWORD *bc = func->byteCode.AddressOf();
|
|
|
|
|
+ *(asBYTE*)bc = asBC_OBJTYPE;
|
|
|
|
|
+ *(asPWORD*)(bc+1) = (asPWORD)ot;
|
|
|
|
|
+ bc += asBCTypeSize[asBCInfo[asBC_OBJTYPE].type];
|
|
|
|
|
+ *(asBYTE*)bc = asBC_CALLSYS;
|
|
|
|
|
+ *(asDWORD*)(bc+1) = factoryId;
|
|
|
|
|
+ bc += asBCTypeSize[asBCInfo[asBC_CALLSYS].type];
|
|
|
|
|
+ *(asBYTE*)bc = asBC_RET;
|
|
|
|
|
+ *(((asWORD*)bc)+1) = (asWORD)func->GetSpaceNeededForArguments();
|
|
|
|
|
+
|
|
|
|
|
+ func->AddReferences();
|
|
|
|
|
+ func->stackNeeded = AS_PTR_SIZE;
|
|
|
|
|
+
|
|
|
|
|
+ // Tell the virtual machine not to clean up the object on exception
|
|
|
|
|
+ func->dontCleanUpOnException = true;
|
|
|
|
|
|
|
|
return func;
|
|
return func;
|
|
|
}
|
|
}
|
|
@@ -3011,7 +3136,7 @@ void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i,
|
|
|
} p;
|
|
} p;
|
|
|
p.func = (void (*)())(i->func);
|
|
p.func = (void (*)())(i->func);
|
|
|
void (asCSimpleDummy::*f)() = p.mthd;
|
|
void (asCSimpleDummy::*f)() = p.mthd;
|
|
|
- obj = (void*)(size_t(obj) + i->baseOffset);
|
|
|
|
|
|
|
+ obj = (void*)(asPWORD(obj) + i->baseOffset);
|
|
|
(((asCSimpleDummy*)obj)->*f)();
|
|
(((asCSimpleDummy*)obj)->*f)();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -3078,7 +3203,7 @@ bool asCScriptEngine::CallObjectMethodRetBool(void *obj, int func)
|
|
|
} p;
|
|
} p;
|
|
|
p.func = (void (*)())(i->func);
|
|
p.func = (void (*)())(i->func);
|
|
|
bool (asCSimpleDummy::*f)() = (bool (asCSimpleDummy::*)())p.mthd;
|
|
bool (asCSimpleDummy::*f)() = (bool (asCSimpleDummy::*)())p.mthd;
|
|
|
- obj = (void*)(size_t(obj) + i->baseOffset);
|
|
|
|
|
|
|
+ obj = (void*)(asPWORD(obj) + i->baseOffset);
|
|
|
return (((asCSimpleDummy*)obj)->*f)();
|
|
return (((asCSimpleDummy*)obj)->*f)();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -3146,7 +3271,7 @@ int asCScriptEngine::CallObjectMethodRetInt(void *obj, int func)
|
|
|
} p;
|
|
} p;
|
|
|
p.func = (void (*)())(i->func);
|
|
p.func = (void (*)())(i->func);
|
|
|
int (asCSimpleDummy::*f)() = (int (asCSimpleDummy::*)())p.mthd;
|
|
int (asCSimpleDummy::*f)() = (int (asCSimpleDummy::*)())p.mthd;
|
|
|
- obj = (void*)(size_t(obj) + i->baseOffset);
|
|
|
|
|
|
|
+ obj = (void*)(asPWORD(obj) + i->baseOffset);
|
|
|
return (((asCSimpleDummy*)obj)->*f)();
|
|
return (((asCSimpleDummy*)obj)->*f)();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -3259,7 +3384,7 @@ void asCScriptEngine::CallObjectMethod(void *obj, void *param, asSSystemFunction
|
|
|
} p;
|
|
} p;
|
|
|
p.func = (void (*)())(i->func);
|
|
p.func = (void (*)())(i->func);
|
|
|
void (asCSimpleDummy::*f)(void *) = (void (asCSimpleDummy::*)(void *))(p.mthd);
|
|
void (asCSimpleDummy::*f)(void *) = (void (asCSimpleDummy::*)(void *))(p.mthd);
|
|
|
- obj = (void*)(size_t(obj) + i->baseOffset);
|
|
|
|
|
|
|
+ obj = (void*)(asPWORD(obj) + i->baseOffset);
|
|
|
(((asCSimpleDummy*)obj)->*f)(param);
|
|
(((asCSimpleDummy*)obj)->*f)(param);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -3343,10 +3468,9 @@ void asCScriptEngine::CallFree(void *obj) const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
-void asCScriptEngine::NotifyGarbageCollectorOfNewObject(void *obj, int typeId)
|
|
|
|
|
|
|
+void asCScriptEngine::NotifyGarbageCollectorOfNewObject(void *obj, asIObjectType *type)
|
|
|
{
|
|
{
|
|
|
- asCObjectType *objType = GetObjectTypeFromTypeId(typeId);
|
|
|
|
|
- gc.AddScriptObjectToGC(obj, objType);
|
|
|
|
|
|
|
+ gc.AddScriptObjectToGC(obj, static_cast<asCObjectType*>(type));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
@@ -3369,16 +3493,10 @@ void asCScriptEngine::GCEnumCallback(void *reference)
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: multithread: The mapTypeIdToDataType must be protected with critical sections in all functions that access it
|
|
// TODO: multithread: The mapTypeIdToDataType must be protected with critical sections in all functions that access it
|
|
|
-/// Urho3D: modified for type id caching
|
|
|
|
|
int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
|
|
int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
|
|
|
{
|
|
{
|
|
|
if( dtIn.IsNullHandle() ) return 0;
|
|
if( dtIn.IsNullHandle() ) return 0;
|
|
|
|
|
|
|
|
- /// Urho3D: check cached type id first
|
|
|
|
|
- int typeId = dtIn.GetCachedTypeId();
|
|
|
|
|
- if( typeId )
|
|
|
|
|
- return typeId;
|
|
|
|
|
-
|
|
|
|
|
// Register the base form
|
|
// Register the base form
|
|
|
asCDataType dt(dtIn);
|
|
asCDataType dt(dtIn);
|
|
|
if( dt.GetObjectType() )
|
|
if( dt.GetObjectType() )
|
|
@@ -3391,7 +3509,7 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
|
|
|
{
|
|
{
|
|
|
if( mapTypeIdToDataType.GetValue(cursor)->IsEqualExceptRefAndConst(dt) )
|
|
if( mapTypeIdToDataType.GetValue(cursor)->IsEqualExceptRefAndConst(dt) )
|
|
|
{
|
|
{
|
|
|
- typeId = mapTypeIdToDataType.GetKey(cursor);
|
|
|
|
|
|
|
+ int typeId = mapTypeIdToDataType.GetKey(cursor);
|
|
|
if( dtIn.GetObjectType() && !(dtIn.GetObjectType()->flags & asOBJ_ASHANDLE) )
|
|
if( dtIn.GetObjectType() && !(dtIn.GetObjectType()->flags & asOBJ_ASHANDLE) )
|
|
|
{
|
|
{
|
|
|
// The the ASHANDLE types behave like handles, but are really
|
|
// The the ASHANDLE types behave like handles, but are really
|
|
@@ -3402,8 +3520,6 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
|
|
|
typeId |= asTYPEID_HANDLETOCONST;
|
|
typeId |= asTYPEID_HANDLETOCONST;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Urho3D: cache the type id for next query
|
|
|
|
|
- dtIn.SetCachedTypeId(typeId);
|
|
|
|
|
return typeId;
|
|
return typeId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3413,12 +3529,12 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
|
|
|
// The type id doesn't exist, create it
|
|
// The type id doesn't exist, create it
|
|
|
|
|
|
|
|
// Setup the basic type id
|
|
// Setup the basic type id
|
|
|
- typeId = typeIdSeqNbr++;
|
|
|
|
|
|
|
+ int typeId = typeIdSeqNbr++;
|
|
|
if( dt.GetObjectType() )
|
|
if( dt.GetObjectType() )
|
|
|
{
|
|
{
|
|
|
if( dt.GetObjectType()->flags & asOBJ_SCRIPT_OBJECT ) typeId |= asTYPEID_SCRIPTOBJECT;
|
|
if( dt.GetObjectType()->flags & asOBJ_SCRIPT_OBJECT ) typeId |= asTYPEID_SCRIPTOBJECT;
|
|
|
else if( dt.GetObjectType()->flags & asOBJ_TEMPLATE ) typeId |= asTYPEID_TEMPLATE;
|
|
else if( dt.GetObjectType()->flags & asOBJ_TEMPLATE ) typeId |= asTYPEID_TEMPLATE;
|
|
|
- else if( dt.GetObjectType()->flags & asOBJ_ENUM ); // TODO: Should we have a specific bit for this?
|
|
|
|
|
|
|
+ else if( dt.GetObjectType()->flags & asOBJ_ENUM ) {} // TODO: Should we have a specific bit for this?
|
|
|
else typeId |= asTYPEID_APPOBJECT;
|
|
else typeId |= asTYPEID_APPOBJECT;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3481,7 +3597,7 @@ int asCScriptEngine::GetTypeIdByDecl(const char *decl) const
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
// This cast is ok, because we are not changing anything in the engine
|
|
// This cast is ok, because we are not changing anything in the engine
|
|
|
asCBuilder bld(const_cast<asCScriptEngine*>(this), 0);
|
|
asCBuilder bld(const_cast<asCScriptEngine*>(this), 0);
|
|
|
- int r = bld.ParseDataType(decl, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(decl, &dt, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return asINVALID_TYPE;
|
|
return asINVALID_TYPE;
|
|
|
|
|
|
|
@@ -3489,13 +3605,13 @@ int asCScriptEngine::GetTypeIdByDecl(const char *decl) const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
-const char *asCScriptEngine::GetTypeDeclaration(int typeId) const
|
|
|
|
|
|
|
+const char *asCScriptEngine::GetTypeDeclaration(int typeId, bool includeNamespace) const
|
|
|
{
|
|
{
|
|
|
asCDataType dt = GetDataTypeFromTypeId(typeId);
|
|
asCDataType dt = GetDataTypeFromTypeId(typeId);
|
|
|
|
|
|
|
|
asASSERT(threadManager);
|
|
asASSERT(threadManager);
|
|
|
asCString *tempString = &threadManager->GetLocalData()->string;
|
|
asCString *tempString = &threadManager->GetLocalData()->string;
|
|
|
- *tempString = dt.Format();
|
|
|
|
|
|
|
+ *tempString = dt.Format(includeNamespace);
|
|
|
|
|
|
|
|
return tempString->AddressOf();
|
|
return tempString->AddressOf();
|
|
|
}
|
|
}
|
|
@@ -3648,21 +3764,7 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, int typeId)
|
|
|
|
|
|
|
|
asCObjectType *objType = dt.GetObjectType();
|
|
asCObjectType *objType = dt.GetObjectType();
|
|
|
|
|
|
|
|
- if( objType->beh.release )
|
|
|
|
|
- {
|
|
|
|
|
- // Call the release behaviour
|
|
|
|
|
- CallObjectMethod(obj, objType->beh.release);
|
|
|
|
|
- }
|
|
|
|
|
- // TODO: interface: shouldn't work on non reference types
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- // Call the destructor
|
|
|
|
|
- if( objType->beh.destruct )
|
|
|
|
|
- CallObjectMethod(obj, objType->beh.destruct);
|
|
|
|
|
-
|
|
|
|
|
- // Then free the memory
|
|
|
|
|
- CallFree(obj);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ReleaseScriptObject(obj, objType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
@@ -3672,14 +3774,19 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, const asIObjectType *type)
|
|
|
if( obj == 0 ) return;
|
|
if( obj == 0 ) return;
|
|
|
|
|
|
|
|
const asCObjectType *objType = static_cast<const asCObjectType *>(type);
|
|
const asCObjectType *objType = static_cast<const asCObjectType *>(type);
|
|
|
- if( objType->beh.release )
|
|
|
|
|
|
|
+ if( objType->flags & asOBJ_REF )
|
|
|
{
|
|
{
|
|
|
- // Call the release behaviour
|
|
|
|
|
- CallObjectMethod(obj, objType->beh.release);
|
|
|
|
|
|
|
+ asASSERT( (objType->flags & asOBJ_NOCOUNT) || objType->beh.release );
|
|
|
|
|
+ if( objType->beh.release )
|
|
|
|
|
+ {
|
|
|
|
|
+ // Call the release behaviour
|
|
|
|
|
+ CallObjectMethod(obj, objType->beh.release);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- // TODO: interface: shouldn't work on non reference types
|
|
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ // TODO: interface: shouldn't work on non reference types
|
|
|
|
|
+
|
|
|
// Call the destructor
|
|
// Call the destructor
|
|
|
if( objType->beh.destruct )
|
|
if( objType->beh.destruct )
|
|
|
CallObjectMethod(obj, objType->beh.destruct);
|
|
CallObjectMethod(obj, objType->beh.destruct);
|
|
@@ -3838,40 +3945,18 @@ asCConfigGroup *asCScriptEngine::FindConfigGroupForObjectType(const asCObjectTyp
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(asCScriptFunction *funcDef) const
|
|
|
|
|
|
|
+asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(const asCScriptFunction *funcDef) const
|
|
|
{
|
|
{
|
|
|
for( asUINT n = 0; n < configGroups.GetLength(); n++ )
|
|
for( asUINT n = 0; n < configGroups.GetLength(); n++ )
|
|
|
{
|
|
{
|
|
|
- if( configGroups[n]->funcDefs.Exists(funcDef) )
|
|
|
|
|
|
|
+ asCScriptFunction *f = const_cast<asCScriptFunction*>(funcDef);
|
|
|
|
|
+ if( configGroups[n]->funcDefs.Exists(f) )
|
|
|
return configGroups[n];
|
|
return configGroups[n];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#ifdef AS_DEPRECATED
|
|
|
|
|
-// deprecated since 2011-10-04
|
|
|
|
|
-int asCScriptEngine::SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess)
|
|
|
|
|
-{
|
|
|
|
|
- asCConfigGroup *group = 0;
|
|
|
|
|
-
|
|
|
|
|
- // Make sure the group name doesn't already exist
|
|
|
|
|
- for( asUINT n = 0; n < configGroups.GetLength(); n++ )
|
|
|
|
|
- {
|
|
|
|
|
- if( configGroups[n]->groupName == groupName )
|
|
|
|
|
- {
|
|
|
|
|
- group = configGroups[n];
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if( group == 0 )
|
|
|
|
|
- return asWRONG_CONFIG_GROUP;
|
|
|
|
|
-
|
|
|
|
|
- return group->SetModuleAccess(module, hasAccess);
|
|
|
|
|
-}
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
// interface
|
|
// interface
|
|
|
asDWORD asCScriptEngine::SetDefaultAccessMask(asDWORD defaultMask)
|
|
asDWORD asCScriptEngine::SetDefaultAccessMask(asDWORD defaultMask)
|
|
|
{
|
|
{
|
|
@@ -4001,20 +4086,11 @@ asUINT asCScriptEngine::GetFuncdefCount() const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
-asIScriptFunction *asCScriptEngine::GetFuncdefByIndex(asUINT index, const char **configGroup) const
|
|
|
|
|
|
|
+asIScriptFunction *asCScriptEngine::GetFuncdefByIndex(asUINT index) const
|
|
|
{
|
|
{
|
|
|
if( index >= registeredFuncDefs.GetLength() )
|
|
if( index >= registeredFuncDefs.GetLength() )
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
- if( configGroup )
|
|
|
|
|
- {
|
|
|
|
|
- asCConfigGroup *group = FindConfigGroupForFuncDef(registeredFuncDefs[index]);
|
|
|
|
|
- if( group )
|
|
|
|
|
- *configGroup = group->groupName.AddressOf();
|
|
|
|
|
- else
|
|
|
|
|
- *configGroup = 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return registeredFuncDefs[index];
|
|
return registeredFuncDefs[index];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -4028,7 +4104,7 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
|
|
|
asUINT n;
|
|
asUINT n;
|
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
|
{
|
|
{
|
|
|
- if( objectTypes[n] && objectTypes[n]->name == type )
|
|
|
|
|
|
|
+ if( objectTypes[n] && objectTypes[n]->name == type && objectTypes[n]->nameSpace == defaultNamespace )
|
|
|
// Let the application recover from this error, for example if the same typedef is registered twice
|
|
// Let the application recover from this error, for example if the same typedef is registered twice
|
|
|
return asALREADY_REGISTERED;
|
|
return asALREADY_REGISTERED;
|
|
|
}
|
|
}
|
|
@@ -4070,7 +4146,6 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
|
|
|
if( token != ttIdentifier || strlen(type) != tokenLen )
|
|
if( token != ttIdentifier || strlen(type) != tokenLen )
|
|
|
return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl);
|
|
return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl);
|
|
|
|
|
|
|
|
- // TODO: namespace: Allow application to specify namespace. Probably with a SetDefaultNamespace
|
|
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
int r = bld.CheckNameConflict(type, 0, 0, "");
|
|
int r = bld.CheckNameConflict(type, 0, 0, "");
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
@@ -4101,7 +4176,7 @@ asUINT asCScriptEngine::GetTypedefCount() const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
-const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup) const
|
|
|
|
|
|
|
+const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const char **nameSpace, const char **configGroup, asDWORD *accessMask) const
|
|
|
{
|
|
{
|
|
|
if( index >= registeredTypeDefs.GetLength() )
|
|
if( index >= registeredTypeDefs.GetLength() )
|
|
|
return 0;
|
|
return 0;
|
|
@@ -4118,6 +4193,12 @@ const char *asCScriptEngine::GetTypedefByIndex(asUINT index, int *typeId, const
|
|
|
*configGroup = 0;
|
|
*configGroup = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if( accessMask )
|
|
|
|
|
+ *accessMask = registeredTypeDefs[index]->accessMask;
|
|
|
|
|
+
|
|
|
|
|
+ if( nameSpace )
|
|
|
|
|
+ *nameSpace = registeredTypeDefs[index]->nameSpace.AddressOf();
|
|
|
|
|
+
|
|
|
return registeredTypeDefs[index]->name.AddressOf();
|
|
return registeredTypeDefs[index]->name.AddressOf();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -4131,14 +4212,14 @@ int asCScriptEngine::RegisterEnum(const char *name)
|
|
|
// Verify if the name has been registered as a type already
|
|
// Verify if the name has been registered as a type already
|
|
|
asUINT n;
|
|
asUINT n;
|
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
for( n = 0; n < objectTypes.GetLength(); n++ )
|
|
|
- if( objectTypes[n] && objectTypes[n]->name == name )
|
|
|
|
|
|
|
+ if( objectTypes[n] && objectTypes[n]->name == name && objectTypes[n]->nameSpace == defaultNamespace )
|
|
|
return asALREADY_REGISTERED;
|
|
return asALREADY_REGISTERED;
|
|
|
|
|
|
|
|
// Use builder to parse the datatype
|
|
// Use builder to parse the datatype
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
bool oldMsgCallback = msgCallback; msgCallback = false;
|
|
|
- int r = bld.ParseDataType(name, &dt);
|
|
|
|
|
|
|
+ int r = bld.ParseDataType(name, &dt, defaultNamespace);
|
|
|
msgCallback = oldMsgCallback;
|
|
msgCallback = oldMsgCallback;
|
|
|
if( r >= 0 )
|
|
if( r >= 0 )
|
|
|
return ConfigError(asERROR, "RegisterEnum", name, 0);
|
|
return ConfigError(asERROR, "RegisterEnum", name, 0);
|
|
@@ -4162,6 +4243,7 @@ int asCScriptEngine::RegisterEnum(const char *name)
|
|
|
st->flags = asOBJ_ENUM | asOBJ_SHARED;
|
|
st->flags = asOBJ_ENUM | asOBJ_SHARED;
|
|
|
st->size = 4;
|
|
st->size = 4;
|
|
|
st->name = name;
|
|
st->name = name;
|
|
|
|
|
+ st->nameSpace = defaultNamespace;
|
|
|
|
|
|
|
|
objectTypes.PushLast(st);
|
|
objectTypes.PushLast(st);
|
|
|
registeredEnums.PushLast(st);
|
|
registeredEnums.PushLast(st);
|
|
@@ -4181,7 +4263,7 @@ int asCScriptEngine::RegisterEnumValue(const char *typeName, const char *valueNa
|
|
|
asCDataType dt;
|
|
asCDataType dt;
|
|
|
int r;
|
|
int r;
|
|
|
asCBuilder bld(this, 0);
|
|
asCBuilder bld(this, 0);
|
|
|
- r = bld.ParseDataType(typeName, &dt);
|
|
|
|
|
|
|
+ r = bld.ParseDataType(typeName, &dt, defaultNamespace);
|
|
|
if( r < 0 )
|
|
if( r < 0 )
|
|
|
return ConfigError(r, "RegisterEnumValue", typeName, valueName);
|
|
return ConfigError(r, "RegisterEnumValue", typeName, valueName);
|
|
|
|
|
|
|
@@ -4220,7 +4302,7 @@ asUINT asCScriptEngine::GetEnumCount() const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// interface
|
|
// interface
|
|
|
-const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup) const
|
|
|
|
|
|
|
+const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const char **nameSpace, const char **configGroup, asDWORD *accessMask) const
|
|
|
{
|
|
{
|
|
|
if( index >= registeredEnums.GetLength() )
|
|
if( index >= registeredEnums.GetLength() )
|
|
|
return 0;
|
|
return 0;
|
|
@@ -4234,9 +4316,15 @@ const char *asCScriptEngine::GetEnumByIndex(asUINT index, int *enumTypeId, const
|
|
|
*configGroup = 0;
|
|
*configGroup = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if( accessMask )
|
|
|
|
|
+ *accessMask = registeredEnums[index]->accessMask;
|
|
|
|
|
+
|
|
|
if( enumTypeId )
|
|
if( enumTypeId )
|
|
|
*enumTypeId = GetTypeIdByDecl(registeredEnums[index]->name.AddressOf());
|
|
*enumTypeId = GetTypeIdByDecl(registeredEnums[index]->name.AddressOf());
|
|
|
|
|
|
|
|
|
|
+ if( nameSpace )
|
|
|
|
|
+ *nameSpace = registeredEnums[index]->nameSpace.AddressOf();
|
|
|
|
|
+
|
|
|
return registeredEnums[index]->name.AddressOf();
|
|
return registeredEnums[index]->name.AddressOf();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -4284,6 +4372,19 @@ asIObjectType *asCScriptEngine::GetObjectTypeByIndex(asUINT index) const
|
|
|
return registeredObjTypes[index];
|
|
return registeredObjTypes[index];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// interface
|
|
|
|
|
+asIObjectType *asCScriptEngine::GetObjectTypeByName(const char *name) const
|
|
|
|
|
+{
|
|
|
|
|
+ for( asUINT n = 0; n < registeredObjTypes.GetLength(); n++ )
|
|
|
|
|
+ {
|
|
|
|
|
+ if( registeredObjTypes[n]->name == name &&
|
|
|
|
|
+ registeredObjTypes[n]->nameSpace == defaultNamespace )
|
|
|
|
|
+ return registeredObjTypes[n];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// interface
|
|
// interface
|
|
|
asIObjectType *asCScriptEngine::GetObjectTypeById(int typeId) const
|
|
asIObjectType *asCScriptEngine::GetObjectTypeById(int typeId) const
|
|
|
{
|
|
{
|
|
@@ -4305,14 +4406,6 @@ asIScriptFunction *asCScriptEngine::GetFunctionById(int funcId) const
|
|
|
return GetScriptFunction(funcId);
|
|
return GetScriptFunction(funcId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#ifdef AS_DEPRECATED
|
|
|
|
|
-// deprecated since 2011-10-03
|
|
|
|
|
-asIScriptFunction *asCScriptEngine::GetFunctionDescriptorById(int funcId) const
|
|
|
|
|
-{
|
|
|
|
|
- return GetScriptFunction(funcId);
|
|
|
|
|
-}
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
// internal
|
|
// internal
|
|
|
bool asCScriptEngine::IsTemplateType(const char *name) const
|
|
bool asCScriptEngine::IsTemplateType(const char *name) const
|
|
|
{
|
|
{
|