Can't copy a string?

Started by
9 comments, last by WitchLord 16 years, 11 months ago
Sorry for this dumb question but after an hour I just can't figure it out. All I want to do is copy one string to another, using scriptstring that comes with AngelScript. I wrote a function that returns a string

ScriptManager::engine->RegisterObjectMethod(className, "const string& getName() const",  asMETHOD(Node, getName),asCALL_THISCALL);

And I want to copy it to another string. (Script)

string copiedString(this.getSceneNode().getName());
DebugPrint(1000, copiedString);

But I get an error:

No matching signatures to 'string(const string)'

(and)

Reference is read only

Ideas?
Advertisement
This one is simple. :) I've just forgotten to register the copy constructor in the scriptstring.cpp file. If you add it, you shouldn't have any more problems copying the strings.

I'll make sure to add the registration of the copy constructor in a future version.

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

Here it is:

static void ConstructString_Generic(asIScriptGeneric *gen){	asCScriptString *thisPointer = (asCScriptString *)gen->GetObject();	ConstructString(thisPointer);}static void ConstructStringCopy_Generic(const asCScriptString &str, asIScriptGeneric *gen){	asCScriptString *thisPointer = (asCScriptString *)gen->GetObject();	ConstructStringCopy(str, thisPointer);}r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT,  "void f(const string &in)",    asFUNCTION(ConstructStringCopy), asCALL_CDECL_OBJLAST); assert( r >= 0 );r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT,  "void f(const string &in)",    asFUNCTION(ConstructStringCopy_Generic), asCALL_GENERIC); assert( r >= 0 );
That fixed the first problem. I still get "Reference is read only" though.
Can you point me to the exact location in the expression that the compiler reports the error for?

I'll try to look into this as soon as I can.

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 one line brings it up:

	string copiedString(this.getSceneNode().getName());


Says column 22, which is between the g of copiedString and (

Functions are as I pasted earlier.
I'm having a similar problem.

string material = "MagnesiumBullet";
@billboardSet.setMaterialName(material);

Results in the following error:
Object handle is not supported for this type

The following registration was used:
result = ScriptManager::engine->RegisterObjectMethod("BillboardSet", "void setMaterialName(const string& inout)", asMETHODPR(BillboardSet, setMaterialName, (const string&), void),asCALL_THISCALL); RakAssert(result>=0)


I'll check the copy constructor again, but string should be a built in type.


This is the line of code where it errors: (as_compiler.cpp)
void asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asSExprContext *ctx){	int op = node->tokenType;	IsVariableInitialized(&ctx->type, node);	if( op == ttHandle )	{		// Verify that the type allow its handle to be taken		if( ctx->type.isExplicitHandle || !ctx->type.dataType.IsObject() || !ctx->type.dataType.GetObjectType()->beh.addref || !ctx->type.dataType.GetObjectType()->beh.release )		{			Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, node);


The objectType appears to be null...

[Edited by - tgraupmann on April 17, 2007 7:43:19 PM]
*News tagenigma.com is my new domain.
Oddly Angelscript doesn't have any problem accessing the type. It just has problems associating a type with a method. If I pass the object and parameters to a function it works fine.

result = ScriptManager::engine->RegisterGlobalFunction("void setMaterialName(BillboardSet@, const string& in)", asFUNCTION(SetMaterialName), asCALL_CDECL); RakAssert(result>=0);
*News tagenigma.com is my new domain.
Quote:Original post by tgraupmann
I'm having a similar problem.

string material = "MagnesiumBullet";
@billboardSet.setMaterialName(material);

Results in the following error:
Object handle is not supported for this type

The following registration was used:
*** Source Snippet Removed ***

I'll check the copy constructor again, but string should be a built in type.


This is the line of code where it errors: (as_compiler.cpp)
*** Source Snippet Removed ***

The objectType appears to be null...


The expression "@billboardSet.setMaterialName(material);" is incorrect. With this you're actually trying to take the handle of the return type of the setMaterialName method, which in your case is void. That's why you're getting the error.

Anyway, I'm back from my vacation now, and I'll do my best to look into Rakkar2's problem as soon as possible.

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

I just want to inform you that I've reproduced the problem and I'm working on the fix now.

	// Test string copy constructor	int r = engine->ExecuteString(0, "string tst(getconststringref()); print(tst);");	if( r != asEXECUTION_FINISHED ) fail = true;	if( printOutput != "test" ) fail = true;


ExecuteString (1, 12) : Error   : Reference is read-only


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