Advertisement

about asCDataType::Format()

Started by May 19, 2005 05:26 AM
4 comments, last by WitchLord 19 years, 6 months ago
Hi. Sorry for my english, please. I've been trying to use your AngelScript library (2.1.0b) in my small project, but unfortunately, it looks like I found a little bug in the following code : // file : as_datatype.cpp // line : 46 asCString asCDataType::Format() const { .... if( isReference || isObjectHandle ) str += "&"; return str; } but no "in", "out" or "inout" were added. So, this seems to be the reason why I can't import function like that : "import void foo_print(string ∈) from foo_module;" because in function asCScriptEngine::BindAllImportedFunctions() we have : ... // file : as_scriptengine.cpp // line : 1672 asCString str = func->GetDeclaration(this); // str == "void foo_print(string&)" // as I think, str should be "void foo_print(string∈)" ... int funcID = GetFunctionIDByDecl(moduleName, str); // funcID == -10 (asINVALID_DECLARATION) ... Am I right and this is a bug ?
Hi, _Dreamer!

Your english is just fine. There's no need to ask for forgiveness.

You have indeed found a bug. The func->GetDeclaration() needs to add the in, out, or inout flags as specified. I'll try to fix this as soon as possible.

May I ask your name, so that I can add you to the credit list, once the bug has been fixed? Or do you prefer that I just refer to you as _Dreamer?

Regards,
Andreas

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
Greetings, Andreas.

My name is Andrey Kraynov. Glad to help you )

And one more thing, if you allow.

After a call to "asIScriptEngine::SaveByteCode()", and then "asIScriptEngine::LoadByteCode()" (like in your test "test_saveload.cpp") all calls to script functions, which take a handles to user defined classes as parameters, fail with error code -6 (asNO_FUNCTION). Script function is like that :

"void do_something(foo_obj @ obj) {}".
Where foo_obj is an application defined class with asOBJ_CLASS flag.

As I think, the problem is in the following code :

// module as_restore.cpp
// line 235
void asCRestore::WriteDataType(asCDataType* dt)
{
WRITE_NUM(dt->tokenType);
WriteObjectType(dt->extendedType);
WRITE_NUM(dt->arrayType);
WRITE_NUM(dt->isReference);
WRITE_NUM(dt->isReadOnly);
WriteObjectType(dt->objectType);
///////////////////////////////////////////////
/* dt->isExplicitHandle has not been written */
///////////////////////////////////////////////
}

because the code for comparing asCDataType is like this:

// module as_datatype.cpp
// line 150
bool asCDataType::operator ==(const asCDataType &dt) const
{
...
//////////////////////////////////////////////////////////////////////
if( isExplicitHandle != dt.isExplicitHandle )
return false;
/*!!! member isExplicitHandle was not saved into bytecode !!!*/
//////////////////////////////////////////////////////////////////////

if( isConstHandle != dt.isConstHandle ) return false;

return true;
}

and that's why function "asCModule::GetFunctionIDByDecl(const char *decl)" return an error.

But maybe you mean, that "asIScriptEngine::SaveByteCode()" should not be called if user defined classes exists ?

Regards,
Andrey.
Thanks, Andrey!

You're right about the second one as well. It is a bug, and I'll correct that as well. I'll hopefully have 2.1.0c out before a couple of days.

Thanks for taking the time to study the code and trying to find the exact location of the bugs, it will give me a good start when searching for the fixes.

Regards,
Andreas

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

The first bug is fixed by replacing asCString asCScriptFunction::GetDeclaration(asCScriptEngine *engine) with the following:

asCString asCScriptFunction::GetDeclaration(asCScriptEngine *engine){	asCString str;	str = returnType.Format();	str += " ";	if( objectType )	{		if( objectType->name != "" )			str += objectType->name + "::";		else			str += "?::";	}	if( name == "" )		str += "?(";	else		str += name + "(";	if( parameterTypes.GetLength() > 0 )	{		int n;		for( n = 0; n < parameterTypes.GetLength() - 1; n++ )		{			str += parameterTypes[n].Format();			if( parameterTypes[n].isReference && inOutFlags.GetLength() > n )			{				if( inOutFlags[n] == 1 ) str += "in";				else if( inOutFlags[n] == 2 ) str += "out";				else if( inOutFlags[n] == 3 ) str += "inout";			}			str += ", ";		}		str += parameterTypes[n].Format();		if( parameterTypes[n].isReference && inOutFlags.GetLength() > n )		{			if( inOutFlags[n] == 1 ) str += "in";			else if( inOutFlags[n] == 2 ) str += "out";			else if( inOutFlags[n] == 3 ) str += "inout";		}	}	str += ")";	return str;}


I'm looking into the second problem right now.

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

The second bug is fixed by adding the following line to the end of void asCRestore::WriteDataType(asCDataType* dt):

WRITE_NUM(dt->isExplicitHandle);


And the following line to the end of void asCRestore::ReadDataType(asCDataType* dt):

READ_NUM(dt->isExplicitHandle);


I'll upload the 2.1.0c as soon as possible with the bug fixes.

Thanks again, for reporting the bugs.

Regards,
Andreas

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