Advertisement

AddScriptSection question

Started by March 24, 2009 05:10 PM
2 comments, last by WitchLord 15 years, 8 months ago
Hello again! As I learned from the documentation all the script sections added to a module with AddScriptSection() will be treated as if one large script, where all declarations are visible to every section, no matter in which order the sections are added to the module. Is this assumption correct? If indeed it is, I think I have found another bug (don't worry no crashes this time :). I have two AngelScript files: file1.as

interface A 
{
}

class B : A 
{
}





file2.as

#include "file1.as" // inclusion handled by CScriptBuilder (metadata OFF)

class C : B
{
}

void main()
{
   A @a = C();
}





This should be legal since it's an upcast to the interface A. However I get the compile error: Can't implicitly convert from 'C@' to 'A@&'. If I put everything into a single file (section) the problem goes away. If I change A to be a class, the problem goes away. I've seen the CScriptBuilder resolve the "includes" by first adding the 'file2' section to the Module and then 'file1', so I guess the problem is about the order of the script sections (when interfaces are involved). Thank you. PS: the fixes for the previous issues worked like a charm!
Quote: Original post by Zeu5
As I learned from the documentation all the script sections added to a module with AddScriptSection() will be treated as if one large script, where all declarations are visible to every section, no matter in which order the sections are added to the module. Is this assumption correct?


Yes, this is correct.


I'll have to investigate this, but it does indeed sound like you've discovered yet another bug.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
The fix is as follows:

as_builder.cpp:

void asCBuilder::CompileClasses(){   ....	// Determine class inheritances and interfaces	for( n = 0; n < classDeclarations.GetLength(); n++ )	{          ...		// Find the base class that this class inherits from		bool multipleInheritance = false;		asCScriptNode *node = decl->node->firstChild->next;		while( node && node->nodeType == snIdentifier )		{                    ....					if( !error )					{						decl->objType->derivedFrom = objType;						objType->AddRef(); Remove this -->						// The derived class inherits all interfaces from the base class						for( unsigned int n = 0; n < objType->interfaces.GetLength(); n++ )						{							if( !decl->objType->Implements(objType->interfaces[n]) )							{								decl->objType->interfaces.PushLast(objType->interfaces[n]);							}							else							{								// Warn if derived class already implements the interface								int r, c;								file->ConvertPosToRowCol(node->tokenPos, &r, &c);								asCString msg;								msg.Format(TXT_INTERFACE_s_ALREADY_IMPLEMENTED, objType->interfaces[n]->GetName());								WriteWarning(file->name.AddressOf(), msg.AddressOf(), r, c);							}						}  <-- Remove this   ....	// Go through each of the classes and register the object type descriptions	for( n = 0; n < classDeclarations.GetLength(); n++ )	{		sClassDeclaration *decl = classDeclarations[n];		// Add all properties and methods from the base class		if( decl->objType->derivedFrom )		{			// TODO: Need to check for name conflict with new class methods			asCObjectType *baseType = decl->objType->derivedFrom;  Add this -->			// The derived class inherits all interfaces from the base class			for( unsigned int n = 0; n < baseType->interfaces.GetLength(); n++ )			{				if( !decl->objType->Implements(baseType->interfaces[n]) )				{					decl->objType->interfaces.PushLast(baseType->interfaces[n]);				}				else				{					// Warn if derived class already implements the interface					int r, c;					decl->script->ConvertPosToRowCol(decl->node->tokenPos, &r, &c);					asCString msg;					msg.Format(TXT_INTERFACE_s_ALREADY_IMPLEMENTED, baseType->interfaces[n]->GetName());					WriteWarning(decl->script->name.AddressOf(), msg.AddressOf(), r, c);				}			}  <-- Add this

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Fix is now available in the SVN.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement